Thursday, August 02, 2007

Coloring nodes

NetBeans brings platform developers a way to improve node labels using simplified subset of HTML tags.
You can see it in action here in the nodes API tutorial.

Supposing you have a subclass of Node or AbstractNode classes, the only thing you need to do is override the getHtmlDisplayName() method.

@Override
public String getHtmlDisplayName() {
String name;

if(updateState) {
name = "Name";
} else {
name = "RED Name";
}

return name;
}


This peace of code returns the name of the node depending on the 'updateState' attribute. If something is wrong then the name is rendered in red.

Also, the 'updateState' can change in any moment, then only you need to do is to fire that display node name has changed with:

fireDisplayNameChange(oldName, newName);


Take in account that the old and new names must be different. If not, the fire method won't have any effect.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.