Re: TreeCellRenderer Doubt
Hi there
I think you have got the TreeCellRenderer for the
whole tree.
What you need is one for each leaf,(using the
getCellRenderer() method) then you
can change the particular one ie:
greenrenderer.setLeafIcon(new ImageIcon("green.gif")
);
> > > setCellRenderer(greenrenderer);
> > > }
else
redrenderer.setLeafIcon(new ImageIcon("red.gif")
);
> > > setCellRenderer(redrenderer);
> > > }
I hope this helps
Phill.
Re: TreeCellRenderer Doubt
Here's an example, I didn't actually change the icons, but the hook is shown below.
Hope this helps.
/**
* Over written to set the tool tips. The tool tip is simply the value, which is
* the string which gets displayed. This is useful when the string is longer than the
* on-screen component is wide.
*/
public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, Object value, boolean sel,
boolean expanded, boolean leaf, int row, boolean hasFocus)
{
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (true)
{
setToolTipText(value.toString());
}
else
{
setToolTipText(null); //no tool tip
}
//Optionally set the icons here
//if (leaf)
//{
//this.setIcon(getDefaultLeafIcon()); //specify which icon heres
//}
return this;
}