• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Questions about JTree

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And maybe you have to append a reload() and an updateUI() method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic