Create Lazy Children with NetBeans Platform 6.5

The NetBeans System Properties Module Tutorial uses Children.Keys to create the children of the node. There are two other (better) ways of doing this instead:
  • org.openide.nodes.ChildFactory. Use when creation of nodes would otherwise take a long time, because it creates them asynchronously. To experiment with it, replace the "AllPropsChildren" class in the tutorial with the following:

    public class AllPropsChildren extends ChildFactory<String> {
        protected boolean createKeys(List<String> keys) {
            Properties p = System.getProperties();
            Enumeration e = p.propertyNames();
            while (e.hasMoreElements()) {
            return true;
        protected Node createNodeForKey(String key) {
            return new OnePropNode(key);

    Read the ChildFactory Javadoc, as well as this example for details.

  • org.openide.nodes.Children.Keys(boolean lazy). From 6.5 Beta onwards (as explained here in the API Changes document), children can be created lazily. I.e., say you have +1000 nodes that need to be created. If the children are lazy, they will only be created as the user makes them visible by scrolling in the explorer view. Until that point, they're not created. The only difference between using the standard org.openide.nodes.Children.Keys and the lazy version is to pass in the boolean true via the constructor (i.e., you're saying 'yes I want my children to be lazy'). This approach is/will be used throughout the IDE to speed up performance and is, thanks to the API, also possible to use in your own implementations.

So, when deciding to use one or the other, ask yourself this: "Will I need to create +1000 nodes?" If your answer is "yes", create the children lazily by passing in true to Children.Keys. If your answer is "no", then use ChildFactory instead, particularly if you anticipate a lot of processing time being required, because ChildFactory will create the children asynchronously.


And here I thought that television and junk food was the only way to create lazy children!

Posted by Tom Wheeler on August 21, 2008 at 04:36 AM PDT #

NetBeans Platform 6.5 is just as effective as television and junk food, Tom!

Posted by Geertjan Wielenga on August 21, 2008 at 07:59 AM PDT #

Although the API change is just an addition of one new constructor, the changes in implementation were huge and I'd like to thank a lot to Tomáš Holý, who managed to implement it and stabilize it.

For 6.5 we decided to stick with this minimalistic API, however, in the future, we would like to have an API for enabling "laziness" similar to ChildFactory, as we found that API a bit nicer.

Posted by Jaroslav Tulach on August 21, 2008 at 07:46 PM 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 2016