This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes After firing how can I leave tree expanded as is? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "After firing how can I leave tree expanded as is?" Watch "After firing how can I leave tree expanded as is?" New topic

After firing how can I leave tree expanded as is?

Brian Snyder2002

Joined: Jan 24, 2002
Posts: 11
After my TreeModel sends me a notice to update, I update my tree as follows:
private void newUser(int indexTo) {
Enumeration enum = getDescendantToggledPaths(this.getAnchorSelectionPath().getParentPath().getParentPath());
System.out.println("enum before = " + enum);
setModel(new DefaultTreeModel(root));
if(enum != null) {
System.out.println("enumAfter = " + enum);
while(enum.hasMoreElements()) {
TreePath path = (TreePath)enum.nextElement();
System.out.println("setting Path = " + path.toString());
I want the tree to leave all of the previously expanded paths expanded. To do this, I record all the paths first by getting an enumeration, I then reset the view to include the new User, and then try to re=expand all the paths. The only path that remains expanded is the selected one.
How can I get all the previously expanded paths to remain open.
I read some of Manfred's postings, but his example opens ALL paths. I just want to open preexisiting ones.
Any ideas?

Java Developer<br />SCJ2P
Joe Gilvary
Ranch Hand

Joined: May 11, 2001
Posts: 152
If your TreeModel told you to update, you probably
do not need to create a new TreeModel. If this is
related to your nonserializable User class from
another post, check the discussion of Tom Rodrigo's JTree question. After you fix the
serialization issue.
I agree. Here's the link:
subject: After firing how can I leave tree expanded as is?
It's not a secret anymore!