| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectjavax.swing.tree.DefaultMutableTreeNodepublic class DefaultMutableTreeNodeextends Objectimplements Cloneable, MutableTreeNode, SerializableMutableTreeNode interface.
Field Summary | |
static Enumeration |
|
protected boolean |
|
protected Vector |
|
protected MutableTreeNode |
|
protected Object |
|
Constructor Summary | |
| |
| |
| |
Method Summary | |
void |
|
Object |
|
boolean |
|
TreeNode |
|
TreeNode |
|
TreeNode |
|
int |
|
int |
|
TreeNode |
|
DefaultMutableTreeNode |
|
int | |
TreeNode |
|
DefaultMutableTreeNode |
|
int |
|
int |
|
DefaultMutableTreeNode |
|
DefaultMutableTreeNode |
|
DefaultMutableTreeNode |
|
TreeNode |
|
TreeNode[] |
|
protected TreeNode[] |
|
DefaultMutableTreeNode |
|
DefaultMutableTreeNode |
|
DefaultMutableTreeNode |
|
TreeNode |
|
TreeNode |
|
int |
|
Object |
|
Object[] |
|
void |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
Methods inherited from class java.lang.Object | |
clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait | |
public static final EnumerationEMPTY_ENUMERATION
An empty enumeration, returned bychildren()if a node has no children.
public DefaultMutableTreeNode()
Creates aDefaultMutableTreeNodeobject. This is equivalent toDefaultMutableTreeNode(null, true).
public DefaultMutableTreeNode(Object userObject)
Creates aDefaultMutableTreeNodeobject with the given user object attached to it. This is equivalent toDefaultMutableTreeNode(userObject, true).
- Parameters:
userObject- the user object (nullpermitted).
public DefaultMutableTreeNode(Object userObject, boolean allowsChildren)
Creates aDefaultMutableTreeNodeobject with the given user object attached to it.
- Parameters:
userObject- the user object (nullpermitted).allowsChildren-trueif the code allows to add child nodes,falseotherwise
public void add(MutableTreeNode child)
Adds a new child node to this node and sets this node as the parent of the child node. The child node must not be an ancestor of this node. If the tree uses theDefaultTreeModel, you must subsequently callDefaultTreeModel.reload(TreeNode).
- Parameters:
child- the child node (nullnot permitted).
- Throws:
IllegalStateException- ifgetAllowsChildren()returnsfalse.IllegalArgumentException- ifisNodeAncestor(TreeNode)returnstrue.IllegalArgumentException- ifchildisnull.
public Object clone()
Returns a clone of the node. The clone contains a shallow copy of the user object, and does not copy the parent node or the child nodes.
- Returns:
- A clone of the node.
public boolean getAllowsChildren()
getAllowsChildren
- Specified by:
- getAllowsChildren in interface TreeNode
- Returns:
- boolean
public TreeNode getChildAfter(TreeNode node)
Returns the next child after the specifiednode, ornullif there is no child after the specifiednode.
- Parameters:
node- a child of this node (nullnot permitted).
- Returns:
- The next child, or
null.
- Throws:
IllegalArgumentException- ifnodeis not a child of this node, or isnull.
public TreeNode getChildAt(int index)
Returns the child node at a given index.
- Specified by:
- getChildAt in interface TreeNode
- Parameters:
index- the index
- Returns:
- the child node
public TreeNode getChildBefore(TreeNode node)
Returns the previous child before the specifiednode, ornullif there is no child before the specifiednode.
- Parameters:
node- a child of this node (nullnot permitted).
- Returns:
- The previous child, or
null.
- Throws:
IllegalArgumentException- ifnodeis not a child of this node, or isnull.
public int getChildCount()
Returns the number of children of this node.
- Specified by:
- getChildCount in interface TreeNode
- Returns:
- the number of children
public TreeNode getFirstChild()
Returns the first child node belonging to this tree node.
- Returns:
- The first child node.
- Throws:
NoSuchElementException- if this tree node has no children.
public DefaultMutableTreeNode getFirstLeaf()
Returns the first leaf node that is a descendant of this node. Recall that a node is its own descendant, so if this node has no children then it is returned as the first leaf.
- Returns:
- The first leaf node.
public int getIndex(TreeNode node)
Returns the index of the specified child node, or -1 if the node is not in fact a child of this node.
- Parameters:
node- the node (nullnot permitted).
- Returns:
- The index of the specified child node, or -1.
- Throws:
IllegalArgumentException- ifnodeisnull.
public TreeNode getLastChild()
Returns the last child node belonging to this tree node.
- Returns:
- The last child node.
- Throws:
NoSuchElementException- if this tree node has no children.
public DefaultMutableTreeNode getLastLeaf()
Returns the last leaf node that is a descendant of this node. Recall that a node is its own descendant, so if this node has no children then it is returned as the last leaf.
- Returns:
- The first leaf node.
public DefaultMutableTreeNode getNextLeaf()
Returns the next leaf node after this tree node.
- Returns:
- The next leaf node, or
null.
public DefaultMutableTreeNode getNextSibling()
Returns the next sibling for this tree node. If this node has no parent, or this node is the last child of its parent, this method returnsnull.
- Returns:
- The next sibling, or
null.
public TreeNode getParent()
Returns the parent node of this node.
- Returns:
- The parent node (possibly
null).
public TreeNode[] getPath()
Returns a path to this node from the root.
- Returns:
- an array of tree nodes
protected TreeNode[] getPathToRoot(TreeNode node, int depth)
getPathToRoot
- Parameters:
node- TODOdepth- TODO
- Returns:
- TreeNode[]
public DefaultMutableTreeNode getPreviousLeaf()
Returns the previous leaf node before this tree node.
- Returns:
- The previous leaf node, or
null.
public DefaultMutableTreeNode getPreviousNode()
getPreviousNode
- Returns:
- DefaultMutableTreeNode
public DefaultMutableTreeNode getPreviousSibling()
Returns the previous sibling for this tree node. If this node has no parent, or this node is the first child of its parent, this method returnsnull.
- Returns:
- The previous sibling, or
null.
public TreeNode getRoot()
Returns the root node by iterating the parents of this node.
- Returns:
- the root node
public TreeNode getSharedAncestor(DefaultMutableTreeNode node)
getSharedAncestor
- Parameters:
node- TODO
- Returns:
- TreeNode
public int getSiblingCount()
Returns the number of siblings for this tree node. If the tree node has a parent, this method returns the child count for the parent, otherwise it returns1.
- Returns:
- The sibling count.
public Object getUserObject()
Returns the user object attached to this node.nullis returned when no user object is set.
- Returns:
- the user object
public void insert(MutableTreeNode node, int index)
Inserts given child node at the given index.
- Specified by:
- insert in interface MutableTreeNode
- Parameters:
node- the child node (nullnot permitted).index- the index.
- Throws:
IllegalArgumentException- ifnodeis null.
public boolean isLeaf()
Returnstrueif this tree node is a lead node (that is, it has no children), andfalse.
- Returns:
- A boolean.
public boolean isNodeAncestor(TreeNode node)
Returnstrueifnodeis an ancestor of this tree node, andfalseotherwise. An ancestor node is any of:If
- this tree node;
- the parent node (if there is one);
- any ancestor of the parent node;
nodeisnull, this method returnsfalse.
- Parameters:
node- the node (nullpermitted).
- Returns:
- A boolean.
public boolean isNodeChild(TreeNode node)
Returnstrueifnodeis a child of this tree node, andfalseotherwise. Ifnodeisnull, this method returnsfalse.
- Parameters:
node- the node (nullpermitted).
- Returns:
- A boolean.
public boolean isNodeDescendant(DefaultMutableTreeNode node)
Returnstrueifnodeis a descendant of this tree node, andfalseotherwise. A descendant node is any of:If
- this tree node;
- the child nodes belonging to this tree node, if there are any;
- any descendants of the child nodes;
nodeisnull, this method returnsfalse.
- Parameters:
node- the node (nullpermitted).
- Returns:
- A boolean.
public boolean isNodeRelated(DefaultMutableTreeNode node)
isNodeRelated
- Parameters:
node- TODO
- Returns:
- boolean
public boolean isNodeSibling(TreeNode node)
Returnstrueif this tree node andnodeshare the same parent. Ifnodeis this tree node, the method returnstrueand ifnodeisnullthis method returnsfalse.
- Parameters:
node- the node (nullpermitted).
- Returns:
- A boolean.
public boolean isRoot()
Tells whether this node is the root node or not.
- Returns:
trueif this is the root node,falseotherwise
public void remove(int index)
Removes the child with the given index from this node.
- Specified by:
- remove in interface MutableTreeNode
- Parameters:
index- the index (in the range0togetChildCount() - 1).
- Throws:
ArrayIndexOutOfBoundsException- ifindexis outside the valid range.
public void remove(MutableTreeNode node)
Removes the given child from this node and sets its parent tonull.
- Specified by:
- remove in interface MutableTreeNode
- Parameters:
node- the child node (nullnot permitted).
- Throws:
IllegalArgumentException- ifnodeis not a child of this node.IllegalArgumentException- ifnodeis null.
public void removeFromParent()
Removes this node from its parent.
- Specified by:
- removeFromParent in interface MutableTreeNode
public void setAllowsChildren(boolean allowsChildren)
Sets the flag that controls whether or not this node allows the addition / insertion of child nodes. If the flag is set tofalse, any existing children are removed.
- Parameters:
allowsChildren- the flag.
public void setParent(MutableTreeNode node)
Set the parent node for this node.
- Specified by:
- setParent in interface MutableTreeNode
- Parameters:
node- the parent node
public void setUserObject(Object userObject)
Sets the user object for this node
- Specified by:
- setUserObject in interface MutableTreeNode
- Parameters:
userObject- the user object