Class JTree.DynamicUtilTreeNode
- All Implemented Interfaces:
Serializable, Cloneable, MutableTreeNode, TreeNode
- Enclosing class:
JTree
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.
- Since:
- 1.2
Field Summary
| 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? |
Fields declared in class DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject | Modifier and Type | Field | Description |
|---|---|---|
protected boolean |
allowsChildren |
true if the node is able to have children |
protected Vector |
children |
array of children, may be null if this node has no children |
static final Enumeration |
EMPTY_ENUMERATION |
An enumeration that is always empty. |
protected MutableTreeNode |
parent |
this node's parent, or null if this node has no parent |
protected Object |
userObject |
optional user object |
Constructor Summary
| Constructor | Description |
|---|---|
DynamicUtilTreeNode |
Creates a node with the specified object as its value and with the specified children. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
Enumeration |
children() |
Subclassed to load the children, if necessary. |
static void |
createChildren |
Adds to parent all the children in children. |
TreeNode |
getChildAt |
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 DefaultMutableTreeNode
add, breadthFirstEnumeration, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildBefore, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString | Modifier and Type | Method | Description |
|---|---|---|
void |
add |
Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array. |
Enumeration |
breadthFirstEnumeration() |
Creates and returns an enumeration that traverses the subtree rooted at this node in breadth-first order. |
Object |
clone() |
Overridden to make clone public. |
Enumeration |
depthFirstEnumeration() |
Creates and returns an enumeration that traverses the subtree rooted at this node in depth-first order. |
boolean |
getAllowsChildren() |
Returns true if this node is allowed to have children. |
TreeNode |
getChildAfter |
Returns the child in this node's child array that immediately follows aChild, which must be a child of this node. |
TreeNode |
getChildBefore |
Returns the child in this node's child array that immediately precedes aChild, which must be a child of this node. |
int |
getDepth() |
Returns the depth of the tree rooted at this node -- the longest distance from this node to a leaf. |
TreeNode |
getFirstChild() |
Returns this node's first child. |
DefaultMutableTreeNode |
getFirstLeaf() |
Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf. |
int |
getIndex |
Returns the index of the specified child in this node's child array. |
TreeNode |
getLastChild() |
Returns this node's last child. |
DefaultMutableTreeNode |
getLastLeaf() |
Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf. |
int |
getLeafCount() |
Returns the total number of leaves that are descendants of this node. |
int |
getLevel() |
Returns the number of levels above this node -- the distance from the root to this node. |
DefaultMutableTreeNode |
getNextLeaf() |
Returns the leaf after this node or null if this node is the last leaf in the tree. |
DefaultMutableTreeNode |
getNextNode() |
Returns the node that follows this node in a preorder traversal of this node's tree. |
DefaultMutableTreeNode |
getNextSibling() |
Returns the next sibling of this node in the parent's children array. |
TreeNode |
getParent() |
Returns this node's parent or null if this node has no parent. |
TreeNode[] |
getPath() |
Returns the path from the root, to get to this node. |
protected TreeNode[] |
getPathToRoot |
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. |
DefaultMutableTreeNode |
getPreviousLeaf() |
Returns the leaf before this node or null if this node is the first leaf in the tree. |
DefaultMutableTreeNode |
getPreviousNode() |
Returns the node that precedes this node in a preorder traversal of this node's tree. |
DefaultMutableTreeNode |
getPreviousSibling() |
Returns the previous sibling of this node in the parent's children array. |
TreeNode |
getRoot() |
Returns the root of the tree that contains this node. |
TreeNode |
getSharedAncestor |
Returns the nearest common ancestor to this node and aNode. |
int |
getSiblingCount() |
Returns the number of siblings of this node. |
Object |
getUserObject() |
Returns this node's user object. |
Object[] |
getUserObjectPath() |
Returns the user object path, from the root, to get to this node. |
void |
insert |
Removes newChild from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex. |
boolean |
isNodeAncestor |
Returns true if anotherNode is an ancestor of this node -- if it is this node, this node's parent, or an ancestor of this node's parent. |
boolean |
isNodeChild |
Returns true if aNode is a child of this node. |
boolean |
isNodeDescendant |
Returns true if anotherNode is a descendant of this node -- if it is this node, one of this node's children, or a descendant of one of this node's children. |
boolean |
isNodeRelated |
Returns true if and only if aNode is in the same tree as this node. |
boolean |
isNodeSibling |
Returns true if anotherNode is a sibling of (has the same parent as) this node. |
boolean |
isRoot() |
Returns true if this node is the root of the tree. |
Enumeration |
pathFromAncestorEnumeration |
Creates and returns an enumeration that follows the path from ancestor to this node. |
Enumeration |
postorderEnumeration() |
Creates and returns an enumeration that traverses the subtree rooted at this node in postorder. |
Enumeration |
preorderEnumeration() |
Creates and returns an enumeration that traverses the subtree rooted at this node in preorder. |
void |
remove |
Removes the child at the specified index from this node's children and sets that node's parent to null. |
void |
remove |
Removes aChild from this node's child array, giving it a null parent. |
void |
removeAllChildren() |
Removes all of this node's children, setting their parents to null. |
void |
removeFromParent() |
Removes the subtree rooted at this node from the tree, giving this node a null parent. |
void |
setAllowsChildren |
Determines whether or not this node is allowed to have children. |
void |
setParent |
Sets this node's parent to newParent but does not change the parent's child array. |
void |
setUserObject |
Sets the user object for this node to userObject. |
String |
toString() |
Returns the result of sending toString() to this node's user object, or the empty string if the node has no user object. |
Methods declared in class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Field Details
hasChildren
protected boolean hasChildren
JTree have children? This property is currently not implemented.childValue
protected Object childValue
loadedChildren
protected boolean loadedChildren
Constructor Details
DynamicUtilTreeNode
public DynamicUtilTreeNode(Object value, Object children)
Vector, or a Hashtable -- even if empty. Otherwise, the node is not allowed to have children.- Parameters:
-
value- theObjectthat is the value for the new node -
children- an array ofObjects, aVector, or aHashtableused to create the child nodes; if any other object is specified, or if the value isnull, then the node is not allowed to have children
Method Details
createChildren
public static void createChildren(DefaultMutableTreeNode parent, Object children)
children. If children is an array or vector all of its elements are added is children, otherwise if children is a hashtable all the key/value pairs are added in the order Enumeration returns them.- Parameters:
-
parent- the parent node -
children- the children
isLeaf
public boolean isLeaf()
- Specified by:
-
isLeafin interfaceTreeNode - Overrides:
-
isLeafin classDefaultMutableTreeNode - Returns:
- true if this node allows children, false otherwise
- See Also:
getChildCount
public int getChildCount()
- Specified by:
-
getChildCountin interfaceTreeNode - Overrides:
-
getChildCountin classDefaultMutableTreeNode - Returns:
- the number of child nodes
loadChildren
protected void loadChildren()
childValue. If childValue is a Vector or array each element is added as a child, if childValue is a Hashtable each key/value pair is added in the order that Enumeration returns the keys.getChildAt
public TreeNode getChildAt(int index)
- Specified by:
-
getChildAtin interfaceTreeNode - Overrides:
-
getChildAtin classDefaultMutableTreeNode - Parameters:
-
index- an index into this node's child array - Returns:
- the TreeNode in this node's child array at the specified index
children
public Enumeration<TreeNode> children()
- Specified by:
-
childrenin interfaceTreeNode - Overrides:
-
childrenin classDefaultMutableTreeNode - Returns:
- an Enumeration of this node's children
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.