File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTree not repainting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree not repainting" Watch "JTree not repainting" New topic
Author

JTree not repainting

pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
I have a jtree in which I pre-select a node. On selecting, I add some text to the node. I have MyTreeCellRenderer which extends DefaultTreeCellRenderer class. I use setText() to paint the tree node. But, when the new text is added, it is not visible. It shows like
<b>100 ...</b> instead <b>100 ABC</b>
But, when I expand the node, the new text is shown properly. Any ideas why is this happening? I think the jtree is not repainting.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Since the node changes size you will need to revalidate instead of repaint... try calling invalidate() or validate() instead of calling repaint() when you change the text of the node...


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

Joined: Oct 22, 2002
Posts: 64
Should I invalidate/validate the panel in which the tree is present or just the jtree?
pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Nathan,
I tried to invaliate/validate both the panel and the jtree, still it does not refresh.
Bhagya Tangutur
Ranch Hand

Joined: Oct 21, 2002
Posts: 88
I tried calling nodechanged method on treeModel.it works fine...I am not sure this is costly operation or not..but it works fine.look for other answers too.


Sun Certified Java Programmer
pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Thanks kumar. Works perfectly as per my requirement.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree not repainting