Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree- setting color for specific nodes in the tree

 
Aruna Devi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to set different color for specific nodes in a JTree based on certain conditions.
When I browsed thru lot of sun tutorials and others, I came across TreeCellRenderer class.
I created a DefaultTreeCellRenderer object and attached to the tree through <treeobject>.setCellRenderer( renderer object ).
Then I have put the condition and depending on that I have used the setTextNonSelectionColor() method to try to the change the color. But then this method changes the color for all nodes made later and not for the specific node only.
Please throw some light on this issue.
I would greatly appreciate the help.
Thanks,
Aruna
 
Craig Snowbarger
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Aruna Devi:
Hi,
I am trying to set different color for specific nodes in a JTree based on certain conditions.
When I browsed thru lot of sun tutorials and others, I came across TreeCellRenderer class.
I created a DefaultTreeCellRenderer object and attached to the tree through <treeobject>.setCellRenderer( renderer object ).
Then I have put the condition and depending on that I have used the setTextNonSelectionColor() method to try to the change the color. But then this method changes the color for all nodes made later and not for the specific node only.
Please throw some light on this issue.
I would greatly appreciate the help.
Thanks,
Aruna

Did you ever figure out how to do this?
 
panyam km
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.,
can u able to send the code and for time being u can check http://www2.gol.com/users/tame/swing/examples/JTreeExamples1.html
bye
panyam
------------------
 
vinod ac
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi aruna devi
follow the link and u will get the answer for ur question
http://www2.gol.com/users/tame/swing/examples/JTreeExamples2.html
 
George Thomas
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some tree cell renderer code:
(ConfigTreeNode is a sub class of DefaultMutableTreeNode)

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic