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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Questions about JTree" Watch "Questions about JTree" New topic
Author

Questions about JTree

aditya sharma
Greenhorn

Joined: Nov 25, 2003
Posts: 1
Hi,
Here is a question that I have about JTree. I want to display hierarchial data using JTree. I dont think I have a problem doing the usual JTree display with collapse and expand. However I would like to implement the following functionality.
When a user right clicks on a node he/she should be able to make that the root of the tree. Can someone help me understand how I can go about implementing this functionality.
Thanks in advance.
Meyer Florian
Ranch Hand

Joined: Oct 20, 2003
Posts: 62
Hi
After adding an action-listener, mouse-listener or whatever, put this code ito the action-method:
((DefaultTreeModel)tree.getModel()).setRoot((DefaultMutableTreeNode)tree.getLastSelectedPathComponent());
that's it.
Praiser
Meyer Florian
Ranch Hand

Joined: Oct 20, 2003
Posts: 62
And maybe you have to append a reload() and an updateUI() method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions about JTree
 
Similar Threads
JTree
JTree
JTree
JTree
JTree