Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

JTree: Expand all node ?

Thread view: 
Mario_5 - 07 Feb 2004 16:02 GMT
How to expand all nodes and disable collapse/expand button?
Christian Kaufhold - 07 Feb 2004 16:10 GMT
> How to expand all nodes and disable collapse/expand button?

http://groups.google.com/groups?q=JTree+expand+all

TreeWillExpandListener

Christian
Luis Munhoz - 07 Jan 2005 17:24 GMT
// If expand is true, expands all nodes in the tree.
// Otherwise, collapses all nodes in the tree.
public void expandAll(JTree tree, boolean expand) {
   TreeNode root = (TreeNode)tree.getModel().getRoot();
   
   // Traverse tree from root
   expandAll(tree, new TreePath(root), expand);
}
private void expandAll(JTree tree, TreePath parent, boolean expand) {
   // Traverse children
   TreeNode node = (TreeNode)parent.getLastPathComponent();
   if (node.getChildCount() >= 0) {
       for (Enumeration e=node.children(); e.hasMoreElements(); ) {
           TreeNode n = (TreeNode)e.nextElement();
           TreePath path = parent.pathByAddingChild(n);
           expandAll(tree, path, expand);
       }
   }
 
   // Expansion or collapse must be done bottom-up
   if (expand) {
       tree.expandPath(parent);
   } else {
       tree.collapsePath(parent);
   }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.