• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTree not updating

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have this JTree in a scroll pane. Each node in the Tree has several attributes, say, for example, Name, Type, Colour, Height. Under the tree, is a combo box. From this, you can select, Type, Colour, Height etc. You select 'Colour' and all the data from the tree is grouped into colours, a new tree is built and .... hey presto, it doesn't appear. The old Tree, grouped by whatever it was grouped by, just sits there.
Here's how I try to show the new tree :

I'm happy with builder.buildTree(), and have tested that seperately, I just can't get the panel to pick up the changes. I tried :

but nothing happened.
What should I try next ?
Thanks,
Kate
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, here is what I had to do. I had my tree in a JScrollPane. I hade to myJPanel.remove(myJScrollPane) and then add it back to the panel again. Then, to actually get the tree to refresh, I tried repaint, but that didn't work. So I had to setVisible(false) and then on the very next line I setVisible(true). That way, it removed the old tree, I called a method that generates a new tree, then added that to the JPanel. Then the panel has to be repainted.
Hope that helps.

Gregg
 
kate damond
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gregg,
thanks for that - you started me off, and eventually, I think I have a concise way to go about it ...
No need to remove the scroll pane, and no need to set the Tree to invisible and back. You just need to set the ScrollPane's ViewPointView, to the new tree. (Actually, you don't even need a new tree, just set the Model for the existing tree - this has the advantage that all existing listeners stay in place) ...


Here, 'newRoot' is a TreeNode returned to me by my builder.buildTree() so it's easy for me to construct just a new Model at that point, rather than a new tree. However, it works if you create your new tree at that point by whatever method, and then do the viewpointView thing
... and the display just updates itself !!!
Hopefully, that helps us both out,
thanks,
Kate
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kate! I'll give that a shot. Should cut down on some of my overhead.
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic