Setting a Node's Tooltip on the Fly

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) { = 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.


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).

Posted by Tom Wheeler on November 11, 2008 at 10:47 PM PST #

Geertjan, I love your blog BUT it's so hard to find anything in your past posts. Apparently 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.... :(

Posted by Bob on November 11, 2008 at 11:53 PM PST #

@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:

Posted by Geertjan on November 11, 2008 at 11:56 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« May 2016