• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree and Icon

 
pradeep selvaraj
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My application has a tree structure representing packages and the classes and interfaces that they contain.

Each package contains classes and interfaces. I wanted to change the default leaf icon and did it with the following code


By using the above code both the classes and the inferfaces can only have the same imageicon. Is there a way to set different imageicon depending on weather they are interfaces or classes.

Thanks

Serish
[ May 27, 2006: Message edited by: serish selvaraj ]
 
pradeep selvaraj
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way by implmenting TreeCellRenderer? If it can be done that way please let me know how?
[ May 28, 2006: Message edited by: serish selvaraj ]
 
krishnakumar K R
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Serish,

You just need implement the TreeCellRenderer ineterface and provide implementation for the getTreeCellRendererComponent method.

Ex::
MyRenderer implements TreeCellRenderer
{

public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,boolean hasFocus)

{
If (value is Class)
{
setIcon();

}
else
{
}


}

}
 
krishnakumar K R
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Serish,

You just need implement the TreeCellRenderer ineterface and provide implementation for the getTreeCellRendererComponent method.

Ex::
MyRenderer implements TreeCellRenderer
{

public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,boolean hasFocus)

{
If (value is Class)
{
setIcon(Class Icon);

}
else
{
setIcon(Interface Icon);
}


}

}

Then add this render obj to the Jtree.

Cheers,
K r I s H.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!