Apache NetBeans Wiki Index

Note: These pages are being reviewed.

Why do my nodes in the Explorer always have an expand-box by them, even though they have no children?

Nodes are not asked for their child nodes until the user tries to expand them - to do otherwise would be very bad for performance. If your Node is not supposed to have child nodes, use Children.LEAF as the children object passed to the constructor. That will eliminate the expand handle.

Remove the expander, if you know the parent-/child-hierarchy at creation time

(Taken from platform-dev mailinglist - author Mark J.Koch - mark@maehem.com)

In my case, our Nodes are backed by actual objects that know their own parent/child hierarchy. First we create our Nodes always as LEAF nodes by default and then set the children (if there are children) later. I have a method in my Node that get’s called whenever our data model changes. First we check if we are already a LEAF node, and if we are, and we have children, we simply initialize the children. If we already have children, we check if our current data model has children here and either update our children keys or explicitly set Children.LEAF if there are no children.

This will properly make the expander disappear when there are no children.

void myModelChanged() {
    if (this.isLeaf()) {
        if (getObject().hasChildren()) {
    } else {
        if (getObject().hasChildren()) {
            // Cause children to regenerate it's key list.
        } else {
            // We no longer have children. Change to leaf.

Apache Migration Information

The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.

This page was exported from http://wiki.netbeans.org/DevFaqNodeChildrenDotLeaf , that was last modified by NetBeans user Markiewb on 2012-12-27T13:42:23Z.

NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.