blob: 4f0ab1e00e574186c205f5c7a8180f91d8b667d2 [file] [log] [blame]
//
// 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.
//
= DevFaqAddingRemovingChildrenDynamically
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqAddingRemovingChildrenDynamically
:description: Apache NetBeans wiki DevFaqAddingRemovingChildrenDynamically
:toc: left
:toc-title:
:syntax: true
=== Can I add or remove children of a node on the fly?
Yes. Have your node subclass link:http://www.netbeans.org/download/dev/javadoc/org-openide-nodes/org/openide/nodes/AbstractNode.html[AbstractNode]
or whatever else you like.
*NB 6 > m9 Specific*:
Implement `ChildFactory`. To create the `Children` object for your Node, pass it to `Children.create()`. When the child list needs updating, call `refresh()` on your `ChildFactory`. Its `createKeys` method will be called again and you can update the set of key objects as needed; Nodes for objects that remain in the list of keys will simply continue to exist; additions and removals will be handled.
*NB 5 And Earlier*:
Have your `Children` object subclass link:http://www.netbeans.org/download/dev/javadoc/org-openide-nodes/org/openide/nodes/Children.Keys.html[Children.Keys].
As needed, call `setKeys()` on the `Children.Keys` object.
Just by passing a larger or smaller (or reordered) list of keys, you will be adding or removing (or reordering) children.
Do not _ever_ try to add/remove children from a node you
did not create (unless it has an API that explicitly gives you permission to do that); occasionally
people try to add child nodes to nodes for things like Java files. If it works at all it's by accident.
---
Applies to: NetBeans 4.0, 4.1, 5.0
=== 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/DevFaqAddingRemovingChildrenDynamically[http://wiki.netbeans.org/DevFaqAddingRemovingChildrenDynamically] ,
that was last modified by NetBeans user Admin
on 2009-11-06T15:36:07Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.