java.lang.Object | |
↳ | javax.swing.tree.DefaultTreeModel |
A simple tree data model that uses TreeNodes. For further information and examples that use DefaultTreeModel, see How to Use Trees in The Java Tutorial.
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 XMLEncoder
.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
asksAllowsChildren | Determines how the isLeaf method figures
out if a node is a leaf node. |
||||||||||
listenerList | Listeners. | ||||||||||
root | Root of the tree. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a tree in which any node can have children.
| |||||||||||
Creates a tree specifying whether any node can have children,
or whether only certain nodes can have children.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a listener for the TreeModelEvent posted after the tree changes.
| |||||||||||
Tells how leaf nodes are determined.
| |||||||||||
Returns the child of parent at index index in the parent's
child array.
| |||||||||||
Returns the number of children of parent.
| |||||||||||
Returns the index of child in parent.
| |||||||||||
Returns an array of all the objects currently registered
as
FooListener s
upon this model. | |||||||||||
Builds the parents of node up to and including the root node,
where the original node is the last element in the returned array.
| |||||||||||
Returns the root of the tree.
| |||||||||||
Returns an array of all the tree model listeners
registered on this model.
| |||||||||||
Invoked this to insert newChild at location index in parents children.
| |||||||||||
Returns whether the specified node is a leaf node.
| |||||||||||
Invoke this method after you've changed how node is to be
represented in the tree.
| |||||||||||
Invoke this method if you've totally changed the children of
node and its childrens children...
| |||||||||||
Invoke this method after you've changed how the children identified by
childIndicies are to be represented in the tree.
| |||||||||||
Invoke this method after you've inserted some TreeNodes into
node.
| |||||||||||
Invoke this method after you've removed some TreeNodes from
node.
| |||||||||||
Invoke this method if you've modified the
TreeNode s upon which
this model depends. | |||||||||||
Invoke this method if you've modified the
TreeNode s upon which
this model depends. | |||||||||||
Message this to remove node from its parent.
| |||||||||||
Removes a listener previously added with addTreeModelListener().
| |||||||||||
Sets whether or not to test leafness by asking getAllowsChildren()
or isLeaf() to the TreeNodes.
| |||||||||||
Sets the root to
root . | |||||||||||
This sets the user object of the TreeNode identified by path
and posts a node changed.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Notifies all listeners that have registered interest for
notification on this event type.
| |||||||||||
Notifies all listeners that have registered interest for
notification on this event type.
| |||||||||||
Notifies all listeners that have registered interest for
notification on this event type.
| |||||||||||
Notifies all listeners that have registered interest for
notification on this event type.
| |||||||||||
Builds the parents of node up to and including the root node,
where the original node is the last element in the returned array.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
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.
Creates a tree in which any node can have children.
root | a TreeNode object that is the root of the tree |
---|
Creates a tree specifying whether any node can have children, or whether only certain nodes can have children.
root | a TreeNode object that is the root of the tree |
---|---|
asksAllowsChildren | a boolean, false if any node can have children, true if each node is asked to see if it can have children |
Adds a listener for the TreeModelEvent posted after the tree changes.
l | the listener to add |
---|
Tells how leaf nodes are determined.
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)).
parent | a node in the tree, obtained from this data source |
---|
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.
parent | a node in the tree, obtained from this data source |
---|
Returns the index of child in parent.
If either the parent or child is null
, returns -1.
parent | a note in the tree, obtained from this data source |
---|---|
child | the node we are interested in |
null
Returns an array of all the objects currently registered
as FooListener
s
upon this model.
FooListener
s are registered using the
addFooListener
method.
You can specify the listenerType
argument
with a class literal,
such as
FooListener.class
.
For example, you can query a
DefaultTreeModel
m
for its tree model listeners with the following code:
TreeModelListener[] tmls = (TreeModelListener[])(m.getListeners(TreeModelListener.class));If no such listeners exist, this method returns an empty array.
listenerType | the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener |
---|
FooListener
s on this component,
or an empty array if no such
listeners have been addedClassCastException | if listenerType
doesn't specify a class or interface that implements
java.util.EventListener |
---|
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.
aNode | the TreeNode to get the path for |
---|
Returns the root of the tree. Returns null only if the tree has no nodes.
Returns an array of all the tree model listeners registered on this model.
TreeModelListener
s
or an empty
array if no tree model listeners are currently registeredInvoked 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.
Returns whether the specified node is a leaf node.
The way the test is performed depends on the
askAllowsChildren
setting.
node | the node to check |
---|
Invoke this method after you've changed how node is to be represented in the tree.
Invoke this method if you've totally changed the children of node and its childrens children... This will post a treeStructureChanged event.
Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree.
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.
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.
Invoke this method if you've modified the TreeNode
s upon which
this model depends. The model will notify all of its listeners that the
model has changed below the given node.
node | the node below which the model has changed |
---|
Invoke this method if you've modified the TreeNode
s upon which
this model depends. The model will notify all of its listeners that the
model has changed.
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.
Removes a listener previously added with addTreeModelListener().
l | the listener to remove |
---|
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.
Sets the root to root
. A null root
implies
the tree is to display nothing, and is legal.
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.
path | path to the node that the user has altered |
---|---|
newValue | the new value from the TreeCellEditor |
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.
source | the node being changed |
---|---|
path | the path to the root node |
childIndices | the indices of the changed elements |
children | the changed elements |
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.
source | the node where new elements are being inserted |
---|---|
path | the path to the root node |
childIndices | the indices of the new elements |
children | the new elements |
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.
source | the node where elements are being removed |
---|---|
path | the path to the root node |
childIndices | the indices of the removed elements |
children | the removed elements |
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.
source | the node where the tree model has changed |
---|---|
path | the path to the root node |
childIndices | the indices of the affected elements |
children | the affected elements |
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.
aNode | the TreeNode to get the path for |
---|---|
depth | an int giving the number of steps already taken towards the root (on recursive calls), used to size the returned array |