• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set multiple icons in a TreeCell?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to set multiple icons in my tree cells. I'm using my custom tree cell renderer that extends the DefaultTreeCell Renderer. In my code, I'm setting the
icons for the cell based on the Node type which seem to be working fine. Now I'd like to add another icon to some of the special nodes.
Now this is what I've been trying (sort of pseudocode)..

public class MyTreeCellRenderer extends DefaultTreeCellRenderer {

public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
final Component c = super.getTreeCellRendererComponent(
tree, cellText, selected,
expanded, leaf, row,
hasFocus);

MyTreeNode node = (MyTreeNode)value;
if (node is of special type){
c.setIcon(image);
}
if (node is of very special type){
FlowLayout layout = new FlowLayout();
layout.setHgap(20);
((JComponent)c).setLayout(layout);
JLabel label = new JLabel(new ImageIcon(AnotherImage));
c.add(label);
}
return c;
}
}

But when I try to add AnotherImage to the very special node, it applies to all the nodes and I see two images in both the nodes (as if it is completely ignoring the if stmt). Any idea whats going on?
Thanks.
-Dan

[ April 21, 2005: Message edited by: S Dan ]

[ April 21, 2005: Message edited by: S Dan ]
[ April 21, 2005: Message edited by: S Dan ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Slime does not pay. Always keep your tiny ad dry.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic