Java: Expand All Or Collapse All Nodes In JTree

Java Swing’s JTree component can be expanded or collapsed at one time through this method. If you notice, there are two expandAll() methods but only one is to be used, the one that is declared as public. The other method that is declared private is a helper method that will recurse itself starting from the root node until all its children have been visited.

The second parameter of the expandAll() method accepts a boolean value telling the JTree to either expand (true) or collapse (false) all the nodes in the tree. I forgot where I got this method from but this is a pretty handy method. Cheers to whoever made this.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *