This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTree not updating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree not updating" Watch "JTree not updating" New topic
Author

JTree not updating

pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
I have a jtree which is constructed initially. On some user action, the jtree has to be recreated. But, even though the jtree is re-created, it does not update on the panel. I am putting the jtree inside a scroll pane and then into the panel.
I am first making jtree and the rootnode object null and initializing it again (for re-creating).
Why is the jtree not getting updated? I prinited the jtree and it has the latest values, but still shows the old values on the panel (screen).
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

you'll need to call fireTreeNodesChanged() or fireTreeStructureChanged() in DefaultTreeModel.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Thanks Nate.
I used scrollpane.getViewport().setView(jtree) method to update the tree.
After setting the view port, the tree does not scroll to the selected node. It scrolls to the top of the tree. Why is that? I am using setSelectionPath() and scrollPathToVisible() method but it does not scroll to selected node.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Take a look at the following code... It generates a tree model randomly... generate a new model a few times and you will see the last node is always selected and is always scrolled to visible. It should give you some pointers on what to do...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree not updating
 
Similar Threads
JTree
JTree
Need help on JTree
jTree with the TreeModel
JTree and JScrollPane