File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set multiple icons in a TreeCell?

 
S Dan
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic