Solved

JTree collapse when reload model

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing to a specific printer tray (HP 806dn printer) 3 83
@SBGen Method 3 38
get weblogic logged in user in java 2 58
micro services spring boot application error 3 146
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now