Solved

JTree collapse when reload model

Posted on 2006-10-21
4
422 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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 62
session migration servlets 2 36
object oriented programming comparison 5 71
SHA2 certs for IIS AND Java? 2 87
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

773 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