// 
//     Licensed to the Apache Software Foundation (ASF) under one
//     or more contributor license agreements.  See the NOTICE file
//     distributed with this work for additional information
//     regarding copyright ownership.  The ASF licenses this file
//     to you under the Apache License, Version 2.0 (the
//     "License"); you may not use this file except in compliance
//     with the License.  You may obtain a copy of the License at
// 
//       http://www.apache.org/licenses/LICENSE-2.0
// 
//     Unless required by applicable law or agreed to in writing,
//     software distributed under the License is distributed on an
//     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
//     KIND, either express or implied.  See the License for the
//     specific language governing permissions and limitations
//     under the License.
//

= DevFaqNodeChildrenDotLeaf
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqNodeChildrenDotLeaf
:description: Apache NetBeans wiki DevFaqNodeChildrenDotLeaf
:toc: left
:toc-title:
:syntax: true

== 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.

[source,java]
----

void myModelChanged() {
    if (this.isLeaf()) {
        if (getObject().hasChildren()) {
            initChildren();
        }
    } else {
        if (getObject().hasChildren()) {
            // Cause children to regenerate it's key list.
            this.getChildren().addNotify();
        } else {
            // We no longer have children. Change to leaf.
            setChildren(Children.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 link:http://wiki.netbeans.org/DevFaqNodeChildrenDotLeaf[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.
