Expand And Collapse All Nodes Of JTree

A quick way to collapse all nodes starting from the root node all the way to its children and sub-children (if there are any) in the JTree class is to use the methods collapseRow() method.

Note that in this code, the starting index is the last node of the JTree’s node list, then looping it until the root node is reached. I purposedly did this because when I tried to set the code to start from the root, all other nodes (whether it has sub-children or not) did not seem to collapse. Only the root’s content was hidden but the root’s children’s collapse state was never changed.

To expand all nodes of the JTree, loop through all nodes and use the expandRow() method.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

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