i don't know how u r managing the level one and level two nodes.,.
if  u r managing with only levels then u can use the following code.,
 
 
public Component getTreeCellRendererComponent(JTree tree, Object value,
  boolean selected, boolean expanded, boolean leaf, int row,
   boolean hasFocus) {
  
    DefaultTreeCellRenderer treeCellRender = (DefaultTreeCellRenderer)
  super.getTreeCellRendererComponent(tree, value, selected, expanded,
           leaf, row, hasFocus);
  DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
  
  if(node.getLevel() == 1) {/// or for u r node how u identify
   treeCellRender.setIcon(new ImageIcon());  <><> icon or gif image u can set
}
}
 
but if u want to change the icon in the same levels then one way is to read the icon names from the Properties
file and try.
On every event u can check the property of the node and u can set the necessary icon that comes from a file.
 
 
 
panyam
----- Original Message -----
Sent: Tuesday, May 29, 2001 01:32 AM
Subject: JTree and DefaultTreeCellRenderer

Hi all.
 Any of you know how could i set an image to a tree.
 i know about the DefaultTreeCellRenderer, and the way to put an image for a leaf or closed(collapsed) or opened(expanded) nodes, But what i need is to set for some elements(supose leaf nodes) an image, and for others another image(e.g).
Obj1 obj1;
Obj2 obj2;
ImageIcon imgObj1=getClass().getResource("obj1.gif");
ImageIcon imgObj2=getClass().getResource("obj2.gif");
.....
so when i add my obj1 in my tree must appear obj1.gif, same whit obj2..you know like JBuilder do in the project browser(if a property is private, the icon is diferent to a public one). It is possible to do..? Have you seen something like this before..? Any idea..?
 
Thanks in advance Romel
------------------------------------------------------
Romel Calero Ramos
Est. Ciencia de la Computación
Universidad de La Habana

Reply via email to