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!

reloading JTree and expanding last selected rows

843805Jun 29 2006 — edited Sep 6 2008
I'm working on an applet that loads the nodes of a JTree from a database. When a node is selected, its data are displayed in a different panel. When a "reload" button is clicked, all the nodes in the JTree are removed except for the root node, and the JTree is recreated from the database. I'm try to get the new JTree to expand and select the rows that were selected before reloading, but I can't get this to work.

Before removing the nodes, I save the currently selected row numbers using JTree.getSelectionRows(). After recreating the JTree, I re-select the previously selected rows and try to expand them:
// tree is the name of the JTree.
tree.setSelectionRows(selected);
for (int i= 0; i < Array.getLength(selected); i++) {
            System.out.println("selected row: " + selected);
tree.scrollRowToVisible(selected[i]);
}
tree.updateUI();

The previously selected rows do not automatically become visible in the resulting JTree. I also tried using tree.expandRow instead of scrollRowToVisible, with the same results.

Any help would be appreciated!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2008
Added on Jun 29 2006
9 comments
703 views