• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree not repainting

 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should I invalidate/validate the panel in which the tree is present or just the jtree?
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nathan,
I tried to invaliate/validate both the panel and the jtree, still it does not refresh.
 
Bhagya Tangutur
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks kumar. Works perfectly as per my requirement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic