?
Solved

Swing- How do i refresh a JTree? tried using repaint, reload and revalidate methods...

Posted on 2003-03-18
8
Medium Priority
?
1,917 Views
Last Modified: 2007-12-19
I am working on an swing application that uses JTree component. i am using HashTable to add the elements to the JTree. The data that is to be displayed will be changing when the user clicks on NExt button. To enable this i am clearing the data in hashtable and adding the new data and readding the component to the JTree. the new data is visible only when i minimize the screen and re maximise. can any one suggest me what i should be doing. i can send the code if required.
chinta_vns@yahoo.com
0
Comment
Question by:chinta_vns
[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
8 Comments
 
LVL 3

Expert Comment

by:msterjev
ID: 8157928
DefaultTreeModel model=(DefaultTreeModel)tree.getTableModel();
model.reload(node)
0
 
LVL 3

Expert Comment

by:msterjev
ID: 8157936
I.E.

You must reload the corresponding node where the items are added or removed! You can reload the root node if the Tree is not very big!
0
 
LVL 1

Expert Comment

by:b612_forever
ID: 8157966
Since you say that it will refresh when you minimise or maximise, I assume that the logic of loading data into JTree is correct and the following is my suggestion.

Add a refresh button and then performed the refresh of JTree by this button.

the code to refresh Jtree may be like this:
MyJTree.revalidate();

If it didn't work properly, try this
MyJTree.setVisible(false);
MyJTree.revalidate();
MyJTree.setVisible(true);

Hope this will help.
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:chinta_vns
ID: 8162352
Thanks for the support. I have tried revalidate, repaint, and reload methods as well. this time i tried to setVisibility to false and then to true. When i try to use
DefaultTreeModel model=(DefaultTreeModel)tree.getTableModel();
model.reload(node)
 it is giving me a compilation error stating that getTableModel() method not found.

Please suggest as the problem persists and is pressing...
Thanks and regards
0
 
LVL 3

Accepted Solution

by:
msterjev earned 200 total points
ID: 8164538
Sorry about the error:

  DefaultTreeModel model=(DefaultTreeModel)tree.getModel();
  //model.reload()
  //or
  model.reload(node);
0
 

Expert Comment

by:CleanupPing
ID: 9058626
chinta_vns:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9727065
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept msterjev's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

800 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