Solved

JTree collapse when reload model

Posted on 2006-10-21
4
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

624 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