No Expansion Icon When No Children (Part 1)

Sometimes you have Nodes with an expansion icon, i.e., the "plus" sign, even though the Object doesn't have Children. Once the user tries to expand the Node, the "plus" sign disappears, and no Children are shown. Kind of misleading because the user thought that there would be Children because the expansion icon was shown. Would be nicer if there were to be no expansion icon if the Object has no Children.

Here's how to solve that, via Children.createLazy:

public class MyNode extends AbstractNode {

    public MyNode(NodeKey key) {
        super(Children.createLazy(new MyCallable(key)), Lookups.singleton(key));

    private static class MyCallable implements Callable<Children> {

        private final NodeKey key;

        private MyCallable(NodeKey key) {
            this.key = key;

        public Children call() throws Exception {
            //Check, somehow, that your key has children,
            //e.g., create "hasChildren" on the object
            //to look in the database to see whether
            //the object has children;
            //if it doesn't have children, return a leaf:
            if (!key.hasChildren()) {
                return Children.LEAF;
            } else {
                return Children.create(new MyChildFactory(key), true);



Now see part 2.



I recently implemented this solution. The explorer tree appeared correctly, but no longer updates correctly; adding and removing nodes don't seem to be triggering the refresh() method in the factory class. For instance, when adding a new child, the underlying data model updates and I can confirm the child is added, but nothing happens in the tree.

My factory class is unchanged and everything is the same except inserting a custom Callable as illustrated above. Is there something extra that needs to be done to make the factory classes do their updates as before?

Posted by Michael Bishop on May 06, 2013 at 08:15 AM PDT #

Hi Michael, have you solved this problem? Sorry for not getting back to this sooner.

Posted by Geertjan on May 24, 2013 at 05:46 AM PDT #

PS: What do you mean by "adding a new child", i.e., how are you adding a new child? A small sample app that demonstrates the problem will be the first step to solving this.

Posted by Geertjan on May 24, 2013 at 08:32 AM PDT #

Part 2 has the solution:

Posted by Geertjan on May 26, 2013 at 08:44 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.


« June 2016