JTree.DynamicUtilTreeNode (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[Serializable](../../../java.base/java/io/Serializable.html "interface in java.io")
, [Cloneable](../../../java.base/java/lang/Cloneable.html "interface in java.lang")
, [MutableTreeNode](tree/MutableTreeNode.html "interface in javax.swing.tree")
, [TreeNode](tree/TreeNode.html "interface in javax.swing.tree")
Enclosing class:
public static class JTree.DynamicUtilTreeNode extends DefaultMutableTreeNode
DynamicUtilTreeNode
can wrap vectors/hashtables/arrays/strings and create the appropriate children tree nodes as necessary. It is dynamic in that it will only create the children as necessary.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans
package. Please see XMLEncoder.
Field Summary
Fields
Modifier and Type | Field | Description |
---|---|---|
protected Object | childValue | Value to create children with. |
protected boolean | hasChildren | Does the this JTree have children? |
protected boolean | loadedChildren | Have the children been loaded yet? |
Constructor Summary
Constructors
Constructor | Description |
---|---|
DynamicUtilTreeNode(Object value,Object children) | Creates a node with the specified object as its value and with the specified children. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
Enumeration<TreeNode> | children() | Subclassed to load the children, if necessary. |
static void | createChildren(DefaultMutableTreeNode parent,Object children) | Adds to parent all the children in children. |
TreeNode | getChildAt(int index) | Subclassed to load the children, if necessary. |
int | getChildCount() | Returns the number of child nodes. |
boolean | isLeaf() | Returns true if this node allows children. |
protected void | loadChildren() | Loads the children based on childValue. |
Methods declared in class javax.swing.tree.DefaultMutableTreeNode
[add](tree/DefaultMutableTreeNode.html#add%28javax.swing.tree.MutableTreeNode%29), [breadthFirstEnumeration](tree/DefaultMutableTreeNode.html#breadthFirstEnumeration%28%29), [clone](tree/DefaultMutableTreeNode.html#clone%28%29), [depthFirstEnumeration](tree/DefaultMutableTreeNode.html#depthFirstEnumeration%28%29), [getAllowsChildren](tree/DefaultMutableTreeNode.html#getAllowsChildren%28%29), [getChildAfter](tree/DefaultMutableTreeNode.html#getChildAfter%28javax.swing.tree.TreeNode%29), [getChildBefore](tree/DefaultMutableTreeNode.html#getChildBefore%28javax.swing.tree.TreeNode%29), [getDepth](tree/DefaultMutableTreeNode.html#getDepth%28%29), [getFirstChild](tree/DefaultMutableTreeNode.html#getFirstChild%28%29), [getFirstLeaf](tree/DefaultMutableTreeNode.html#getFirstLeaf%28%29), [getIndex](tree/DefaultMutableTreeNode.html#getIndex%28javax.swing.tree.TreeNode%29), [getLastChild](tree/DefaultMutableTreeNode.html#getLastChild%28%29), [getLastLeaf](tree/DefaultMutableTreeNode.html#getLastLeaf%28%29), [getLeafCount](tree/DefaultMutableTreeNode.html#getLeafCount%28%29), [getLevel](tree/DefaultMutableTreeNode.html#getLevel%28%29), [getNextLeaf](tree/DefaultMutableTreeNode.html#getNextLeaf%28%29), [getNextNode](tree/DefaultMutableTreeNode.html#getNextNode%28%29), [getNextSibling](tree/DefaultMutableTreeNode.html#getNextSibling%28%29), [getParent](tree/DefaultMutableTreeNode.html#getParent%28%29), [getPath](tree/DefaultMutableTreeNode.html#getPath%28%29), [getPathToRoot](tree/DefaultMutableTreeNode.html#getPathToRoot%28javax.swing.tree.TreeNode,int%29), [getPreviousLeaf](tree/DefaultMutableTreeNode.html#getPreviousLeaf%28%29), [getPreviousNode](tree/DefaultMutableTreeNode.html#getPreviousNode%28%29), [getPreviousSibling](tree/DefaultMutableTreeNode.html#getPreviousSibling%28%29), [getRoot](tree/DefaultMutableTreeNode.html#getRoot%28%29), [getSharedAncestor](tree/DefaultMutableTreeNode.html#getSharedAncestor%28javax.swing.tree.DefaultMutableTreeNode%29), [getSiblingCount](tree/DefaultMutableTreeNode.html#getSiblingCount%28%29), [getUserObject](tree/DefaultMutableTreeNode.html#getUserObject%28%29), [getUserObjectPath](tree/DefaultMutableTreeNode.html#getUserObjectPath%28%29), [insert](tree/DefaultMutableTreeNode.html#insert%28javax.swing.tree.MutableTreeNode,int%29), [isNodeAncestor](tree/DefaultMutableTreeNode.html#isNodeAncestor%28javax.swing.tree.TreeNode%29), [isNodeChild](tree/DefaultMutableTreeNode.html#isNodeChild%28javax.swing.tree.TreeNode%29), [isNodeDescendant](tree/DefaultMutableTreeNode.html#isNodeDescendant%28javax.swing.tree.DefaultMutableTreeNode%29), [isNodeRelated](tree/DefaultMutableTreeNode.html#isNodeRelated%28javax.swing.tree.DefaultMutableTreeNode%29), [isNodeSibling](tree/DefaultMutableTreeNode.html#isNodeSibling%28javax.swing.tree.TreeNode%29), [isRoot](tree/DefaultMutableTreeNode.html#isRoot%28%29), [pathFromAncestorEnumeration](tree/DefaultMutableTreeNode.html#pathFromAncestorEnumeration%28javax.swing.tree.TreeNode%29), [postorderEnumeration](tree/DefaultMutableTreeNode.html#postorderEnumeration%28%29), [preorderEnumeration](tree/DefaultMutableTreeNode.html#preorderEnumeration%28%29), [remove](tree/DefaultMutableTreeNode.html#remove%28int%29), [remove](tree/DefaultMutableTreeNode.html#remove%28javax.swing.tree.MutableTreeNode%29), [removeAllChildren](tree/DefaultMutableTreeNode.html#removeAllChildren%28%29), [removeFromParent](tree/DefaultMutableTreeNode.html#removeFromParent%28%29), [setAllowsChildren](tree/DefaultMutableTreeNode.html#setAllowsChildren%28boolean%29), [setParent](tree/DefaultMutableTreeNode.html#setParent%28javax.swing.tree.MutableTreeNode%29), [setUserObject](tree/DefaultMutableTreeNode.html#setUserObject%28java.lang.Object%29), [toString](tree/DefaultMutableTreeNode.html#toString%28%29)
Field Details
hasChildren
protected boolean hasChildren
Does the thisJTree
have children? This property is currently not implemented.childValue
protected Object childValue
Value to create children with.loadedChildren
protected boolean loadedChildren
Have the children been loaded yet?Constructor Details
DynamicUtilTreeNode
public DynamicUtilTreeNode(Object value,Object children)
Creates a node with the specified object as its value and with the specified children. For the node to allow children, the children-object must be an array of objects, aVector
, or aHashtable
-- even if empty. Otherwise, the node is not allowed to have children.
Parameters:
value
- theObject
that is the value for the new node
children
- an array ofObject
s, aVector
, or aHashtable
used to create the child nodes; if any other object is specified, or if the value isnull
, then the node is not allowed to have childrenMethod Details
createChildren
Adds to parent all the children in
children
. Ifchildren
is an array or vector all of its elements are added is children, otherwise ifchildren
is a hashtable all the key/value pairs are added in the orderEnumeration
returns them.
Parameters:
parent
- the parent node
children
- the childrenisLeaf
public boolean isLeaf()
Returns true if this node allows children. Whether the node allows children depends on how it was created.
Specified by:
[isLeaf](tree/TreeNode.html#isLeaf%28%29)
in interface[TreeNode](tree/TreeNode.html "interface in javax.swing.tree")
Overrides:
[isLeaf](tree/DefaultMutableTreeNode.html#isLeaf%28%29)
in class[DefaultMutableTreeNode](tree/DefaultMutableTreeNode.html "class in javax.swing.tree")
Returns:
true if this node allows children, false otherwise
See Also:
JTree.DynamicUtilTreeNodegetChildCount
public int getChildCount()
Returns the number of child nodes.
Specified by:
[getChildCount](tree/TreeNode.html#getChildCount%28%29)
in interface[TreeNode](tree/TreeNode.html "interface in javax.swing.tree")
Overrides:
[getChildCount](tree/DefaultMutableTreeNode.html#getChildCount%28%29)
in class[DefaultMutableTreeNode](tree/DefaultMutableTreeNode.html "class in javax.swing.tree")
Returns:
the number of child nodesloadChildren
protected void loadChildren()
Loads the children based onchildValue
. IfchildValue
is aVector
or array each element is added as a child, ifchildValue
is aHashtable
each key/value pair is added in the order thatEnumeration
returns the keys.getChildAt
public TreeNode getChildAt(int index)
Subclassed to load the children, if necessary.
Specified by:
[getChildAt](tree/TreeNode.html#getChildAt%28int%29)
in interface[TreeNode](tree/TreeNode.html "interface in javax.swing.tree")
Overrides:
[getChildAt](tree/DefaultMutableTreeNode.html#getChildAt%28int%29)
in class[DefaultMutableTreeNode](tree/DefaultMutableTreeNode.html "class in javax.swing.tree")
Parameters:
index
- an index into this node's child array
Returns:
the TreeNode in this node's child array at the specified indexchildren
Subclassed to load the children, if necessary.
Specified by:
[children](tree/TreeNode.html#children%28%29)
in interface[TreeNode](tree/TreeNode.html "interface in javax.swing.tree")
Overrides:
[children](tree/DefaultMutableTreeNode.html#children%28%29)
in class[DefaultMutableTreeNode](tree/DefaultMutableTreeNode.html "class in javax.swing.tree")
Returns:
an Enumeration of this node's children