JTree collapse when reload model

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.
aquaswAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
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
 
dbrownell83Commented:
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
 
objectsCommented:
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
 
aquaswAuthor Commented:
objects thanks,
When I do it, I get flickering in the tree. It is not display good.
Any solution?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.