• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

JTree and Icon

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic