I dont know if this is the best way, but look at:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/tree/DefaultTreeCellRenderer.html#getTreeCellRendererComponent(javax.swing.JTree,%20java.lang.Object,%20boolean,%20boolean,%20boolean,%20int,%20boolean)
(the getTreeCellRendererComponent() method)
You can do an if statement like:
if( value == specialLeaf){
setBackground(Color.green);
}
Message was edited by:
Nether
When I do that, it doens't change the background color. I tried setBackgroundNonSelectionColor, which states that it changes the background for just that node, but it changes the background for all of the nodes.
i.e.:
if (value == myNode) {
System.out.println("Here's my node");
setBackgroundNonSelectionColor(Color.RED);
}
Here's the rest of the function, in case I'm calling something I shouldn't be:
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
// above snippet goes here
return this;
}
> I tried setBackgroundNonSelectionColor, which
> states that it changes the background for just that
> node, but it changes the background for all of the
> nodes.
How about you try this:
if(node == myNode){
setColor(red)
}
else{
setColor(blue)
}
What might be happening is that it sets the color to red, but then it never sets it back again. For instance, if you are drawing with Graphics, when you change the color with g.setColor(c), it will stay that color until another piece of code changes it back.
Hope this works.