If it's just adding something, use

 return new ProxyLookup(new Lookup[] { 
   super.getLookup(), Lookups.fixed(
     new Object[] { something, somethingElse }


If there's only one object, substitute Lookups.singleton ( someObject ).

If you need to change the content of the lookup on the fly, it's a little more complicated, but not too much. Use the above ProxyLookup technique if there's a Lookup returned by the superclass and you still want to use its content. What you'll use to change content on the fly is the combination of AbstractLookup (which, as fate would have it, is not actually abstract), and InstanceContent, which is a grab bag of stuff you can add to and remove from.

The result will look something like this:

 class MyNode extends AbstractNode {
  private final InstanceContent lookupContents = new InstanceContent();
  private final Lookup myLookup = new AbstractLookup (lookupContents);
  public Lookup getLookup() {
      return myLookup;

When you need to change the contents of your lookup, just call InstanceContent.set() and pass it a Collection with whatever should now be in the lookup, e.g.

 lookupContents.set (Collections.singleton(new Whatzit()));

Source: NetBeans FAQ

Parent Category: Other API Tips