Disabling the collapse event of the JTree is possible by adding a listener to it. There may be times where you want your JTree to be always in expanded mode hence disabling its collapse event is the only way to go.
Add a TreeWillExpandListener to the JTree, make the treeWillCollapse() method throw ExpandVetoException and that should do it.
|
1 2 3 4 5 6 |
tree.addTreeWillExpandListener(new TreeWillExpandListener() { public void treeWillExpand(TreeExpansionEvent e) { } public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException { throw new ExpandVetoException(e); } }); |
Thanks a lot for the code to disable this. I was struggling to get it right.