Hide Unhide Nodes Of JTree

jtreeI have read a number of articles that featured source codes from forums and sites on how to show or hide nodes of a JTree. The easiest code that I found that was easy to understand and use are source files labeled InvisibleNode.java and InvisibleTreeModel.java.

You can easily search that in Google to get those files. The result that I wanted to accomplish was to show only 2 checkbox leaf nodes at most if the last leaf node of the parent node has a button labeled HIDE and is clicked. I know it is hard to visualize so I included a snapshot of my JTree.

My JTree‘s parent nodes contain leaf nodes that have checkboxes and a button at the end of each parent node if there consists more than 2 checkbox leaf nodes per parent node. By default the button is labeled HIDE. If I click on it, it will show only 2 checkboxes while hiding the rest (except the button) and the button’s label will change to SHOW. If I click on the button again, it will all all sibling leaf nodes.

Those two Java source files easily did the trick in hiding and showing tree nodes.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

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