aquasw
asked on
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.
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.
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.
you'll need to save whats collapsed and whats not and expand the tree yourself as required.
ASKER
objects thanks,
When I do it, I get flickering in the tree. It is not display good.
Any solution?
When I do it, I get flickering in the tree. It is not display good.
Any solution?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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(TreeM
// and here, try make some record of the current expansion state
// and then recreate it... errr.... somehow. sorry, im not sure
}
});