| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
DefaultMutableTreeNode root = …;
DefaultTreeModel model = new DefaultTreeModel(root);
Based on 25 examples
JTree tree = …;
DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
Based on 18 examples
public class DefaultTreeModel extends Object implements Serializable, TreeModel
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 {@link java.beans.XMLEncoder}.
Field Summary | |
---|---|
protected boolean |
asksAllowsChildren
Determines how the isLeaf method figures
out if a node is a leaf node. |
protected EventListenerList |
listenerList
Listeners. |
protected TreeNode |
root
Root of the tree. |
Constructor Summary | |
---|---|
DefaultTreeModel(TreeNode root) Creates a tree in which any node can have children. |
|
DefaultTreeModel(TreeNode root, boolean asksAllowsChildren) Creates a tree specifying whether any node can have children, or whether only certain nodes can have children. |
Method Summary | |
---|---|
void |
Adds a listener for the TreeModelEvent posted after the tree changes. |
boolean |
Tells how leaf nodes are determined. |
protected void |
fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children) Notifies all listeners that have registered interest for notification on this event type. |
protected void |
fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children) Notifies all listeners that have registered interest for notification on this event type. |
protected void |
fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) Notifies all listeners that have registered interest for notification on this event type. |
protected void |
fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) Notifies all listeners that have registered interest for notification on this event type. |
Object |
Returns the child of parent at index index in the parent's child array. |
int |
getChildCount(Object parent) Returns the number of children of parent. |
int |
getIndexOfChild(Object parent, Object child) Returns the index of child in parent. |
EventListener[] |
getListeners(Class listenerType) Returns an array of all the objects currently registered as FooListener s
upon this model.
|
TreeNode[] |
getPathToRoot(TreeNode aNode) Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. |
protected TreeNode[] |
getPathToRoot(TreeNode aNode, int depth) Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. |
Object |
getRoot() Returns the root of the tree. |
TreeModelListener[] |
Returns an array of all the tree model listeners registered on this model. |
void |
insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index) Invoked this to insert newChild at location index in parents children. |
boolean |
Returns whether the specified node is a leaf node. |
void |
nodeChanged(TreeNode node) Invoke this method after you've changed how node is to be represented in the tree. |
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. |
void |
nodeStructureChanged(TreeNode node) Invoke this method if you've totally changed the children of node and its childrens children... |
void |
nodesWereInserted(TreeNode node, int[] childIndices) Invoke this method after you've inserted some TreeNodes into node. |
void |
nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren) Invoke this method after you've removed some TreeNodes from node. |
void |
reload() Invoke this method if you've modified the s upon which this model depends. |
void |
Invoke this method if you've modified the s upon which this model depends. |
void |
Message this to remove node from its parent. |
void |
Removes a listener previously added with addTreeModelListener(). |
void |
setAsksAllowsChildren(boolean newValue) Sets whether or not to test leafness by asking getAllowsChildren() or isLeaf() to the TreeNodes. |
void |
Sets the root to root .
|
void |
valueForPathChanged(TreePath path, Object newValue) This sets the user object of the TreeNode identified by path and posts a node changed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean asksAllowsChildren
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.
protected EventListenerList listenerList
protected TreeNode root
Constructor Detail |
---|
public DefaultTreeModel(TreeNode root)
root
- a TreeNode object that is the root of the treepublic DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
root
- a TreeNode object that is the root of the treeasksAllowsChildren
- a boolean, false if any node can
have children, true if each node is asked to see if
it can have childrenMethod Detail |
---|
public void addTreeModelListener(TreeModelListener l)
l
- the listener to addpublic boolean asksAllowsChildren()
protected void fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children)
source
- the node being changedpath
- the path to the root nodechildIndices
- the indices of the changed elementschildren
- the changed elementsprotected void fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children)
source
- the node where new elements are being insertedpath
- the path to the root nodechildIndices
- the indices of the new elementschildren
- the new elementsprotected void fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children)
source
- the node where elements are being removedpath
- the path to the root nodechildIndices
- the indices of the removed elementschildren
- the removed elementsprotected void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children)
source
- the node where the tree model has changedpath
- the path to the root nodechildIndices
- the indices of the affected elementschildren
- the affected elementspublic Object getChild(Object parent, int index)
parent
- a node in the tree, obtained from this data sourceindex
public int getChildCount(Object parent)
parent
- a node in the tree, obtained from this data sourcepublic int getIndexOfChild(Object parent, Object child)
null
, returns -1.
parent
- a note in the tree, obtained from this data sourcechild
- the node we are interested innull
public EventListener[] getListeners(Class listenerType)
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 addedpublic TreeNode[] getPathToRoot(TreeNode aNode)
aNode
- the TreeNode to get the path forprotected TreeNode[] getPathToRoot(TreeNode aNode, int depth)
aNode
- the TreeNode to get the path fordepth
- an int giving the number of steps already taken towards
the root (on recursive calls), used to size the returned arraypublic Object getRoot()
public TreeModelListener[] getTreeModelListeners()
TreeModelListener
s
or an empty
array if no tree model listeners are currently registeredpublic void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
newChild
parent
index
public boolean isLeaf(Object node)
askAllowsChildren
setting.
node
- the node to checkpublic void nodeChanged(TreeNode node)
node
public void nodesChanged(TreeNode node, int[] childIndices)
node
childIndices
public void nodeStructureChanged(TreeNode node)
node
public void nodesWereInserted(TreeNode node, int[] childIndices)
node
childIndices
public void nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren)
node
childIndices
removedChildren
public void reload()
public void reload(TreeNode node)
node
- the node below which the model has changedpublic void removeNodeFromParent(MutableTreeNode node)
node
public void removeTreeModelListener(TreeModelListener l)
l
- the listener to removepublic void setAsksAllowsChildren(boolean newValue)
newValue
public void setRoot(TreeNode root)
root
. A null root
implies
the tree is to display nothing, and is legal.
root
public void valueForPathChanged(TreePath path, Object newValue)
path
newValue
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |