java.lang.Objectjavax.swing.tree.DefaultTreeModel
public class 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.
| 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 |
addTreeModelListener(TreeModelListener l)
Adds a listener for the TreeModelEvent posted after the tree changes. |
|
boolean |
asksAllowsChildren()
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 |
getChild(Object parent,
int index)
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. |
|
|
getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListeners
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[] |
getTreeModelListeners()
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 |
isLeaf(Object node)
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 TreeNodes upon which this model depends. |
|
void |
reload(TreeNode node)
Invoke this method if you've modified the TreeNodes upon which this model depends. |
|
void |
removeNodeFromParent(MutableTreeNode node)
Message this to remove node from its parent. |
|
void |
removeTreeModelListener(TreeModelListener l)
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 |
setRoot(TreeNode root)
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 TreeNode root
protected EventListenerList listenerList
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.
| Constructor Detail |
|---|
public DefaultTreeModel(TreeNode root)
root - a TreeNode object that is the root of the treeDefaultTreeModel(TreeNode, boolean)public 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 childrenasksAllowsChildren| Method Detail |
|---|
public void setAsksAllowsChildren(boolean newValue)
public boolean asksAllowsChildren()
asksAllowsChildrenpublic void setRoot(TreeNode root)
root. A null root implies
the tree is to display nothing, and is legal.
public Object getRoot()
public int getIndexOfChild(Object parent, Object child)
null, returns -1.
getIndexOfChild in interface TreeModelparent - a note in the tree, obtained from this data sourcechild - the node we are interested in
nullpublic Object getChild(Object parent, int index)
parent - a node in the tree, obtained from this data source
public int getChildCount(Object parent)
getChildCount in interface TreeModelparent - a node in the tree, obtained from this data source
public boolean isLeaf(Object node)
askAllowsChildren setting.
node - the node to check
asksAllowsChildren,
TreeModel.isLeaf(java.lang.Object)public void reload()
public void valueForPathChanged(TreePath path, Object newValue)
valueForPathChanged in interface TreeModelpath - path to the node that the user has alterednewValue - the new value from the TreeCellEditorpublic void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int index)
public void removeNodeFromParent(MutableTreeNode node)
public void nodeChanged(TreeNode node)
public void reload(TreeNode node)
node (PENDING).
public void nodesWereInserted(TreeNode node, int[] childIndices)
public void nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren)
public void nodesChanged(TreeNode node, int[] childIndices)
public void nodeStructureChanged(TreeNode node)
public 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 array
public void addTreeModelListener(TreeModelListener l)
addTreeModelListener in interface TreeModell - the listener to addremoveTreeModelListener(javax.swing.event.TreeModelListener)public void removeTreeModelListener(TreeModelListener l)
removeTreeModelListener in interface TreeModell - the listener to removeaddTreeModelListener(javax.swing.event.TreeModelListener)public TreeModelListener[] getTreeModelListeners()
TreeModelListeners
or an empty
array if no tree model listeners are currently registeredaddTreeModelListener(javax.swing.event.TreeModelListener),
removeTreeModelListener(javax.swing.event.TreeModelListener)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 elementsEventListenerListprotected 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 elementsEventListenerListprotected 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 elementsEventListenerListprotected 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 elementsEventListenerListpublic <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListeners
upon this model.
FooListeners 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:
listenerType - the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener
FooListeners on this component,
or an empty array if no such
listeners have been added
ClassCastException - if listenerType
doesn't specify a class or interface that implements
java.util.EventListenergetTreeModelListeners()Ces informations proviennent du site de http://java.sun.com
Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :
Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.
Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.
Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.
Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.
Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.
Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.
7 mots clés dont 0 définis manuellement (plus d'information...).
Avertissement
Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.
Recherche (afficher)
Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
Citation (masquer)