• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

JTree not updating

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

 
money grubbing section goes here:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic