Geertjan's Blog

  • November 11, 2008

Setting a Node's Tooltip on the Fly

Geertjan Wielenga
Product Manager
I expanded my API today. It now looks like this:
package org.netbeans.demo;
public interface User {
public String getName();
public String getDescription();

As a result, the other module, i.e., the one that provides the service, now needs to update its service provider class:

package org.netbeans.demo;
import org.netbeans.demo.User;
public class User1 implements User {
private String name;
private String description;
public String getName() {
return name;
public String getDescription() {
return description;
public void setName(String name) {
this.name = name;
public void setDescription(String description) {
this.description = description;

So, now, in the editor component, I add the user name and user description to the InstanceContent when the Enter key is pressed in the editor, which updates the node hierarchy even though the node hierarchy is in a different module to where the editor component is found:

Finally, in order to handle both the name and the description, the Children.Keys subclass now works with a string array, instead of a string, to get the name and description which are used in the creation of the node hierarchy:

public class UserChildren extends Children.Keys<String[]> implements LookupListener {
private Lookup.Result result = null;
private ArrayList<String[]> userDetails = new ArrayList();
public UserChildren() {
result = Utilities.actionsGlobalContext().lookupResult(User.class);
public void resultChanged(LookupEvent lookupEvent) {
Collection c = result.allInstances();
for (User user : c) {
userDetails.add(new String[]{user.getName(), user.getDescription()});
protected void addNotify() {
protected Node[] createNodes(String[] userDetails) {
return new Node[]{new PropNode(userDetails)};
private class PropNode extends AbstractNode {
private PropNode(String[] userDetails) {

Notice that AbstractNode.setShortDescription sets the tooltip. I also tried working with AbstractNode.setIconBaseWithExtension, but that unfortunately assumes that the image is within the module, so it is not possible to have the user select an external image (i.e., on disk) for setting a node's icon on the fly.

Join the discussion

Comments ( 3 )
  • Tom Wheeler Wednesday, November 12, 2008

    I guess you could override getIcon() to have it return an ImageIcon which is loaded from any location you wish (e.g. using java.awt.Toolkit's getImage method).

  • Bob Wednesday, November 12, 2008

    Geertjan, I love your blog BUT it's so hard to find anything in your past posts. Apparently blogs.sun.com doesn't have tagging? It's a real tragedy you have an avalanche of awesome material here but there's no way to access it but the search feature.... :(

  • Geertjan Wednesday, November 12, 2008

    @Tom, thanks! I'll investigate that.

    @Bob, thanks and you can use the Search on the left of this blog or, even better, I've been gradually linking to relevant topics from the NetBeans Developer FAQ:


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha

Integrated Cloud Applications & Platform Services