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 ]