| public class javax.swing.tree DefaultTreeModel
|
Java SE 6 |
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 JavaBeansTM
has been added to the java.beans package.
Please see java.beans.XMLEncoder.
| version | 1.57 04/12/06 |
| Fields | |||
|---|---|---|---|
| protected TreeNode | root Root of the tree. | ||
| protected EventListenerList | listenerList Listeners. | ||
| protected boolean | asksAllowsChildren Details
Determines how the isLeaf method figures
out if a node is a leaf node. If true, a node is a leaf
node if it does not allow children. (If it allows
children, it is not a leaf node, even if no children
are present.) That lets you distinguish between folder
nodes and file nodes in a file system, for example.
If this value is false, then any node which has no children is a leaf node, and any node may acquire children.
| ||
| Constructors | |||||||
|---|---|---|---|---|---|---|---|
| public | DefaultTreeModel(TreeNode root) Details
Creates a tree in which any node can have children.
| ||||||
| public | DefaultTreeModel(TreeNode root, boolean asksAllowsChildren) Details
Creates a tree specifying whether any node can have children,
or whether only certain nodes can have children.
| ||||||
| Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| public void | addTreeModelListener(TreeModelListener l) Details
Adds a listener for the TreeModelEvent posted after the tree changes.
| ||||||||||
| public boolean | asksAllowsChildren() Details
Tells how leaf nodes are determined.
| ||||||||||
| protected void | fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children) Details
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
| ||||||||||
| protected void | fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children) Details
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
| ||||||||||
| protected void | fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) Details
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
| ||||||||||
| protected void | fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) Details
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
| ||||||||||
| public void | insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index) Invoked this to insert newChild at location index in parents children. This will then message nodesWereInserted to create the appropriate event. This is the preferred way to add children as it will create the appropriate event. | ||||||||||
| public void | nodeChanged(TreeNode node) Invoke this method after you've changed how node is to be represented in the tree. | ||||||||||
| public void | nodesChanged(TreeNode node, int[] childIndices) Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree. | ||||||||||
| public void | nodeStructureChanged(TreeNode node) Invoke this method if you've totally changed the children of node and its childrens children... This will post a treeStructureChanged event. | ||||||||||
| public void | nodesWereInserted(TreeNode node, int[] childIndices) Invoke this method after you've inserted some TreeNodes into node. childIndices should be the index of the new elements and must be sorted in ascending order. | ||||||||||
| public void | nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren) Invoke this method after you've removed some TreeNodes from node. childIndices should be the index of the removed elements and must be sorted in ascending order. And removedChildren should be the array of the children objects that were removed. | ||||||||||
| public void | reload() Invoke this method if you've modified the TreeNodes upon which
this model depends. The model will notify all of its listeners that the
model has changed.
| ||||||||||
| public void | reload(TreeNode node) Details
Invoke this method if you've modified the TreeNodes upon which
this model depends. The model will notify all of its listeners that the
model has changed below the given node.
| ||||||||||
| public void | removeNodeFromParent(MutableTreeNode node) Message this to remove node from its parent. This will message nodesWereRemoved to create the appropriate event. This is the preferred way to remove a node as it handles the event creation for you. | ||||||||||
| public void | removeTreeModelListener(TreeModelListener l) Details
Removes a listener previously added with addTreeModelListener().
| ||||||||||
| public void | valueForPathChanged(TreePath path, Object newValue) This sets the user object of the TreeNode identified by path and posts a node changed. If you use custom user objects in the TreeModel you're going to need to subclass this and set the user object of the changed node to something meaningful. | ||||||||||
| Properties | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| public void | setAsksAllowsChildren(boolean newValue) Sets whether or not to test leafness by asking getAllowsChildren() or isLeaf() to the TreeNodes. If newvalue is true, getAllowsChildren() is messaged, otherwise isLeaf() is messaged. | ||||||||||
| public Object | getChild(Object parent, int index) Details
Returns the child of parent at index index in the parent's
child array. parent must be a node previously obtained from
this data source. This should not return null if index
is a valid index for parent (that is index >= 0 &&
index < getChildCount(parent)).
| ||||||||||
| public int | getChildCount(Object parent) Details
Returns the number of children of parent. Returns 0 if the node
is a leaf or if it has no children. parent must be a node
previously obtained from this data source.
| ||||||||||
| public int | getIndexOfChild(Object parent, Object child) Details
Returns the index of child in parent.
If either the parent or child is null, returns -1.
| ||||||||||
| public boolean | isLeaf(Object node) Details
Returns whether the specified node is a leaf node.
The way the test is performed depends on the
askAllowsChildren setting.
| ||||||||||
| public EventListener[]<T> | getListeners(Class listenerType) Details
Returns an array of all the objects currently registered
as FooListeners
upon this model.
FooListeners are registered using the
addFooListener method.
You can specify the TreeModelListener[] tmls = (TreeModelListener[])(m.getListeners(TreeModelListener.class));If no such listeners exist, this method returns an empty array.
| ||||||||||
| public TreeNode[] | getPathToRoot(TreeNode aNode) Details
Builds the parents of node up to and including the root node,
where the original node is the last element in the returned array.
The length of the returned array gives the node's depth in the
tree.
| ||||||||||
| protected TreeNode[] | getPathToRoot(TreeNode aNode, int depth) Details
Builds the parents of node up to and including the root node,
where the original node is the last element in the returned array.
The length of the returned array gives the node's depth in the
tree.
| ||||||||||
| public void | setRoot(TreeNode root) Sets the root to root. A null root implies
the tree is to display nothing, and is legal.
| ||||||||||
| public Object | getRoot() Details
Returns the root of the tree. Returns null only if the tree has
no nodes.
| ||||||||||
| public TreeModelListener[] | getTreeModelListeners() Details
Returns an array of all the tree model listeners
registered on this model.
| ||||||||||
| About DocWeb · Bundles · Export · Export All | Top 10 · Statistics · Login |
| About Sun · Contact · Privacy · Terms of Use · Trademarks | Java SE 6 · Copyright © 1994-2009 Sun Microsystems, Inc.All rights reserved. Use is subject to license terms |
![]() |
![]() |
|