Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Maintain and Restore JTree expansion state

843806Mar 25 2008 — edited Mar 28 2008
Hi there,

I'm having a little trouble while trying to restore JTree expansion state. While using the method
Enumeration en = jtree.getExpandedDescendants(new TreePath(jtree.getModel().getRoot()));
It returns me all the actual expanded nodes. No problem with that. The problem is that the TreePaths it stores aren't doing their thing when I try to restore the JTree state.
I do the following:
while(en.hasMoreElements()){
        TreePath tp = (TreePath)en.nextElement();
        jtreeQware.expandPath(tp);
}
Unfortunately it does not expand the tree paths! And if i try to get the row index based on the tree path it always return -1 ! Really odd...
int row = jtree.getRowForPath(tp)
This ALWAYS return -1. Anyone got an idea of what am I doing wrong?? Need help, please.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2008
Added on Mar 25 2008
4 comments
496 views