Geertjan's Blog

  • August 21, 2008

Create Lazy Children with NetBeans Platform 6.5

Geertjan Wielenga
Product Manager
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.

Join the discussion

Comments ( 3 )
  • Tom Wheeler Thursday, August 21, 2008

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

  • Geertjan Wielenga Thursday, August 21, 2008

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

  • Jaroslav Tulach Friday, August 22, 2008

    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.

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