In my app, I'm trying to make sure the selected treenode is shown, meaning it is expanded all the way down, and also scrolled into view.
How can I programmatically implement this (meaning all the tree node's parent nodes are expanded, and it's scrolled into view)?
A tree node only has a reference to its children, not its parent, and there's no way I could find to scroll the tree to a node.
I have tried to look for ITreeNode.EnsureVisible method or similar, but in vain.
Related
I use DataViewTreeCtrl to show a parents-children tree and I want to remove a parent (Container) once the last child of it is removed. I could not find a method to get the container/parent of a child from GetSelections() and the only way I can seem to think of is writing an algorithm that will iterate through the entire tree to find the selected item and its parent that will be called each time an item is to be removed.
I have a page with a huge tree component (scrollable) and an edit component where I can edit the selected node. After I edit the selected node in the edit window, I have an ajax event that updates the tree component.
My problem is that the tree updates 100% but the selected node is now scrolled out of view. How can I scroll back to the selected node. Or is there a way to update just the selected node in the tree instead of updating the tree completely?
If the treenode is still selected you could try calling this after the edit
document.getElementsByClassName("ui-treenode-selected")[0].scrollIntoView()
I encountered exactly the same situation, here's my solution, based on JavaScript:
$('.scrollable-tree-container').each(function(index) {
var position = $(this).find('.ui-state-highlight').position();
if (typeof position != 'undefined') {
$(this).scrollTop(position.top + $(this).scrollTop() - 300);
}
});
How does it work?
Specify the container providing the scroll bar
Look for a highlighted node
Read its position and scroll there
You might want to add additional selectors to avoid side effects on other components. I've subtracted 300px here since I had a total tree height of 800px. This way, the selected node will be somewhere in the middle (and not on top).
The undefined check is only necessary if you cannot asure that there's always one node selected when calling the function.
I am using javafx 2.2. I have an circle object which moves as the mouse moves. However, there are new objects on the scene. I want to position this object always on top of the others.
With OPENGL, you just draw this circle LAST in each frame in the rendering loop, but with JavaFX, how can this be achieved?
Most of the time just use Node.toFront()
Invoke node.toFront() on starting to drag the node.
The drawing order of a node is determined by the node's position in the node's parent's ObservableList of children. node.toFront() will move the node to the end of the parent's child list so that it will be the last thing rendered for that parent.
Beware that for some layout types (such as HBox), the order of the node in the parent's child list also determine's the nodes layout position in the list as well as the node's rendering order.
For 3D work alter z order
If you are doing 3D work, then adjusting the z-coordinate of the node can also place the node on top of other nodes.
For cross parent dragging use a stack
If you want to drag the node out of it's parent and into another parent, then you could make the root of the scene a stack, remove the node from it's initial parent, place it at the top of the scene stack, drag it to it's new parent, and on drag finished, remove the node from the scene stack and place it into the appropriate position in it's new parent's child list.
Background/Context:
I have a HBox as a parent and many child Nodes (Buttons, TextFields, Labels…). The HBox is a child of other container (BorderPane/VBox/Grid)
My questions:
How do I dynamically remove/exclude the parent (HBox) and all its children from layout?
I am looking for some three-state property on Node (like in Microsoft WPF):
Visible – visible and participate in layout
Collapsed – is not visible and do not participate in layout (applies to its children as well)
Hidden – is not visible but participate in layout
http://msdn.microsoft.com/en-us/library/ms590101.aspx
What options does JavaFX offer?
My solutions so far:
hBox.setManaged(false);
this work only for HBox, its children are still present
root.getChildren().remove(hBoxTop);
root.getChildren().add(hBoxTop);
Well, this looks like it could work.., but for example in case of root being BorderPane, once I remove/add and remove the HBox, the space after it remains unused. I already tried requestLayout() but id does not force thr rrot to fill it. Am I missing something? Is it correct approach to this problem?
Edited:
Well, I got this working.
Dynamically removing and adding for this specific case can be achieved by:
Remove:
root.setTop(null);
Add:
root.setTop(hBoxTop);
When I did not call setTop(null) on removal, BorderPane still reserved space for HBox (even after removal from its children).
IMHO: it is not very good model as it is parent-container specific. For example if I change, BorderPane to VBox a I had to change these methods as well. For VBox, remove/add on children collection works but I need to remember index so that HBox appears at same place after calling add.
Using root.setTop(null) is not a good idea because as you say it's specific to BorderPane.
I think the best solution is to use:
root.getChildren().remove(yourPane);
And use layout methods to place your other childrens as you want.
But maybe you should not use a BorderPane in the first place with the behaviors you want in your application.
Notice you can also do root.getChildren().clear() to remove all component and add it again to your layout but differently.
I'm creating a jsf which contains a rich:tree. When the tree is going to render, data is pulled from a database to render the tree.
Next to the tree is a chart. The charts content is linked to the selected node in the tree.
When the tree is rendered, no node is selected -> no chart.
Is it possible to select the root node as default selected node and how can I achieve this?
Thanks in advance
You may use the adviseNodeSelected attribute of the tree.
MethodBinding pointing at a method accepting an org.richfaces.component.UITree with return of java.lang.Boolean type. If returned value is: java.lang.Boolean. TRUE, a particular treeNode is selected; java.lang.Boolean.FALSE, a particular treeNode is unselected; null, a particular treeNode saves the current state
http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf?tab=info