aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree not updating" Watch "JTree not updating" New topic
Author

JTree not updating

kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
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
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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


GenRocket - Experts at Building Test Data
kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Thanks Kate! I'll give that a shot. Should cut down on some of my overhead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree not updating