wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Expanding a Specific Node in JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Expanding a Specific Node in JTree" Watch "Expanding a Specific Node in JTree" New topic

Expanding a Specific Node in JTree

sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
hi ranchers,

i stuck up with a problem of tree expanding.

i have one tree
+ one
- 1 // leaf node
- 2 // leaf node
- 3 // leaf node
- 4 // leaf node
- 5 // leaf node
- 6 // leaf node

My requirement is,
i have to expand the parent of a leaf node in the tree.

Suppose if I pass object of �6�, the tree should expand
subthree� node.

i have tried in several ways to expand the tree
1) expandRow(int) -- expanding the immidiate childes of root only
2) expandPath(TreePath) -- I can't get path of a node. because mutable node have getPath() method, but it returns array of TreeNode[] not a TreePath.

Please help me.

Thanks in advance.
[ April 19, 2005: Message edited by: sasi kala ]
sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68

thanks for the reply. i understand the way how tree works and done some coding to find the solution.

What i understand is "to expand a specific node in the tree, we need to expand all its parent nodes". My problem is, i have object of the node which has to be expanded in hand. and i don't know ancestors of that node.

what i observed in JTree is,
1) we have to store all nodes of a tree in some where (like Map), becasue to search any node the JTree needs only that node object (not even new node object with the same data).

2) row numbers of tree nodes are not static. When we pass a row number to "expandRow(row)" method, suppose n, the tree will expand nth visible node from the root.

i solve my problem like below

And finally i came out of the tree expanding problem.
[ April 27, 2005: Message edited by: sasi kala ]
I agree. Here's the link: http://aspose.com/file-tools
subject: Expanding a Specific Node in JTree
Similar Threads
Jtree child selection problem
JTree - expanding nodes
JTree expansion & collapse programatically
Expand Lazy Loaded JTree
Lazy fetching JTree