Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JTree collapse when reload model

Posted on 2006-10-21
4
Medium Priority
?
445 Views
Last Modified: 2008-02-26
Hi,
I'm using a tree in my swing application. The tree model is changing all the time.
When I reload the tree model, the tree collapses and show it first hierarchy.
How can I set the tree to keep it collapses/expansion status after model reload?
Thanks.
0
Comment
Question by:aquasw
  • 2
4 Comments
 
LVL 1

Expert Comment

by:dbrownell83
ID: 17782061
hmm.

i would try adding a TreeModelListener to the TreeModel...

TreeModel model = new YourModel();
JTree tree = new JTree(model);

model.addTreeModelListener(
new TreeModelListener() {
public void treeStructureChanged(TreeModelEvent e) {
// and here, try make some record of the current expansion state
// and then recreate it... errr.... somehow.  sorry, im not sure
}

});
0
 
LVL 92

Expert Comment

by:objects
ID: 17782954
you can't, as its displaying different data.
you'll need to save whats collapsed and whats not and expand the tree yourself as required.
0
 

Author Comment

by:aquasw
ID: 17782979
objects thanks,
When I do it, I get flickering in the tree. It is not display good.
Any solution?
0
 
LVL 92

Accepted Solution

by:
objects earned 1500 total points
ID: 17782982
don't reload your model :)
if the data is changing so much that u need to reload the model how can you retain the previously expaned nodes anyway (as they may no longer be there)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question