• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jtree multiple icons  RSS feed

 
Tamer Badr
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Jtrees just support having three icons, one for the default icon, one for the open node, and one for the closed node.
I need to have more icons, I have tree levels, and I want every level to have a set of three icons, can this be done?
Thanks.
 
nitin goswami
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As per my understanding you want to have specific icons at specific level of the tree. To do this youhave to right a derived class of DefaultTreeCellRenderer and you have to extend method:
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
if(Condition 1)
setIcon("image1")
if(Condition 2)
setIcon("image2")
...........
and so on......

}

Inside this method, your condition could be anything like you can check the object class or level or anything to decide the appropriate icon...
Ya then you have to set this TreeCellRenderer for your tree.

Let me know if you want anything else or if you feel that I've not understood your problem/requirment properly.

Thanks
-Nitin
 
Tamer Badr
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I really need, I'll try it and let you know, thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!