posted 12 years ago
Hi Sven,
You can create a method that will iterate over all the visible rows in the JTree and collapse them. You can use the methods getRowCount() and collapseRow() to do this.
Then simply expand the previously selected path. You can use getLeadSelectionPath() and expandPath() here.
It might be necessary to store the selected path before collapsing all the rows, you'll have to see for yourself. Depending on your taste, you can also choose to collapse the children of the selected path after you've done all this.
Finally, add a TreeSelectionListener to the JTree that calls this method.
Warning, the value of getRowCount() may change as you make calls to collapseRow(), so make sure to keep checking it. Either that, or iterate the tree in reverse order.