Enhanced Change Notifications for Lookup in NetBeans Platform 6.9

A typical stumbling block for newbies to Lookup goes like this: you've created a Result object and then set a LookupListener on that object. Now you're listening to the context (of the application or of a specific window) and then... nothing happens!

You then find yourself adding the line in bold below:

public void componentOpened() {
    result = Utilities.actionsGlobalContext().lookupResult(Customer.class);
    resultChanged(new LookupEvent(result));

That line in bold is for the opening of the window. At that point, there's no change in the Lookup yet. So you manually call the resultChanged method, passing in 'null' or, more elegantly, a new LookupEvent with the current Result object.

However, in 6.9, a nice enhancement was added:


In other words, adding the LookupListener is all you need to do. No need to call the resultChanged anymore. I tried that today, during the training with the students in Burkina Faso... and code that would not have worked in 6.8 (i.e., code without the last line in the method above), now works perfectly in 6.9.

Should make a big difference for newbies working with Lookup in the NetBeans Platform.

In other news. The training in Burkina Faso was a success for everyone involved. Patrick Honoré Ouoba, Hyacinthe Bosso Tingueri, Emmanuel Zimian Paregueba Ouedraogo, Oumar Abdou Nassur Konombo, Constantin Drabo, and Fatimazahra Hakkou are the latest NetBeans Platform Certified Associates. We're 'meeting' (Skype, plus WebEx) again in a month, to port one of their applications to the NetBeans Platform together.


You don't need to call result.allItems(), but there is no guarantee you should not initialize your structures based on actual content of the lookup.

Posted by Jaroslav Tulach on June 20, 2010 at 09:12 PM PDT #

This is a welcome change. But I think we need a clear writeup on how to migrate from old code to new one. Escpecially for newbies who are looking at the old samples (like me), it will be very helpfull (Unless every samples is migrated).

Posted by Janice on October 05, 2010 at 04:50 AM PDT #

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.


« July 2015