Link to home
Start Free TrialLog in
Avatar of aquasw
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.
Avatar of dbrownell83
dbrownell83

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
}

});
Avatar of Mick Barry
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.
Avatar of aquasw

ASKER

objects thanks,
When I do it, I get flickering in the tree. It is not display good.
Any solution?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial