File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree not updating

 
pavan in
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you'll need to call fireTreeNodesChanged() or fireTreeStructureChanged() in DefaultTreeModel.
 
pavan in
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic