public class TreeModelEvent extends EventObject
 警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已被添加到java.beans包中。 请参阅XMLEncoder 。 
| Modifier and Type | Field and Description | 
|---|---|
| protected int[] | childIndices
              确定孩子的位置的指标。 
             | 
| protected Object[] | children
              被删除的孩子 
             | 
| protected TreePath | path
              到已更改节点的父节点的路径。 
             | 
source| Constructor and Description | 
|---|
| TreeModelEvent(Object source, Object[] path)
              用于在节点结构以某种方式更改时创建事件,将修改后的子树的根目录的路径标识为对象数组。 
             | 
| TreeModelEvent(Object source, Object[] path, int[] childIndices, Object[] children)
              用于在更改,插入或删除节点时创建事件,将修改后的项目的父项路径标识为对象数组。 
             | 
| TreeModelEvent(Object source, TreePath path)
              用于在节点结构以某种方式更改时创建事件,将修改后的子树的根路径标识为TreePath对象。 
             | 
| TreeModelEvent(Object source, TreePath path, int[] childIndices, Object[] children)
              用于在更改,插入或删除节点时创建事件,将修改后的项目的父项路径标识为TreePath对象。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| int[] | getChildIndices()
              返回子索引的值。 
             | 
| Object[] | getChildren()
              返回由标识节点的子对象 
              getPath在由指定的位置getChildIndices。 | 
| Object[] | getPath()
              从事件包装的TreePath实例获取对象数组的便利方法。 
             | 
| TreePath | getTreePath()
              对于所有事件,除了treeStructureChanged,返回已更改节点的父节点。 
             | 
| String | toString()
              返回显示和标识此对象属性的字符串。 
             | 
getSourceprotected TreePath path
protected int[] childIndices
protected Object[] children
public TreeModelEvent(Object source, Object[] path, int[] childIndices, Object[] children)
int 。 
           该数组中的索引必须按顺序排列,从最低到最高。 
           对于更改,模型中的索引完全对应于UI中当前显示的项目的索引。 因此,如果索引不是按照它们的顺序,那么这并不重要。 但是,在多次插入或删除后,UI中的项目不再对应于模型中的项目。 因此,必须正确指定索引的插入和删除。
 对于插入,索引表示在插入发生之后树的最终状态。 由于索引必须按顺序指定,所以最自然的处理方法是从最低索引开始进行插入,并以最高的方式工作。 累加一个Integer对象,指定插入位置,然后将Vector转换为int的数组以创建事件。 当postition-index等于零时,节点将被插入列表的开头。 当位置索引等于列表的大小时,节点在列表的末尾(附加到)处被“插入”。 
 对于删除,索引代表树的初始状态,在删除发生之前。 由于索引必须按顺序指定,最自然的处理方法是使用删除计数器。 首先将计数器初始化为零,然后通过列表从最低到最高开始工作。 每次删除时,将删除计数器的当前值添加到发生删除的索引位置,并使用addElement()将结果附加到“删除位置向量”。 然后递增删除计数器。 因此,存储在Vector中的索引位置反映了所有以前删除的效果,因此它们表示每个对象在初始树中的位置。 (你也可以开始在最高指数,对最低工作恢复,积累的删除,位置的载体,当您去使用insertElementAt(Integer, 0) )。但是你产生初始位置的矢量,你再需要的向量转换Integer对象到一个int的数组来创建事件。 
笔记:
insertNodeInto方法DefaultTreeModel , insertElementAt附加到Vector当索引与向量的大小匹配时。 所以即使向量为空也可以使用insertElementAt(Integer, 0) 。 null 。 source - 负责生成事件的对象(通常事件对象的创建者通过其值为 
            this ) 
           path - 一个Object的数组,用于标识修改后的项目的父对象的路径,其中数组的第一个元素是存储在根节点的对象,最后一个元素是存储在父节点的对象 
           childIndices -的阵列int指定删除的项目的索引值。 
            索引必须按照排序顺序,从最低到最高 
           children - 包含插入,删除或更改对象的Object数组 
           TreePath 
           public TreeModelEvent(Object source, TreePath path, int[] childIndices, Object[] children)
TreeModelEvent(Object,Object[],int[],Object[]) 。 
          source - 负责生成事件的对象(通常事件对象的创建者通过 
            this作为其值) 
           path - 一个TreePath对象,用于标识修改的项目的父项的路径 
           childIndices - 一个 
            childIndices的数组, 
            int修改后的项目的索引值 
           children - 包含插入,删除或更改对象的Object数组 
           TreeModelEvent(Object,Object[],int[],Object[]) 
           public TreeModelEvent(Object source, Object[] path)
Note:
JTree collapses all nodes under the specified node, so that only its immediate children are visible.
source - 负责生成事件的对象(通常事件对象的创建者通过其值为 
            this ) 
           path - 一个Object数组,用于标识修改子树根的路径,其中数组的第一个元素是存储在根节点的对象,最后一个元素是存储在更改的节点上的对象 
           TreePath 
           public TreeModelEvent(Object source, TreePath path)
TreeModelEvent(Object,Object[]) 。 
          source - 负责生成事件的对象(通常事件对象的创建者通过其值为 
            this ) 
           path - 一个TreePath对象,用于标识更改的路径。 
            在DefaultTreeModel中,此对象包含一个用户数据对象数组,但是TreePath的一个子类可以使用一些完全不同的机制 - 例如,一个节点ID号 
           TreeModelEvent(Object,Object[]) 
           public TreePath getTreePath()
getChildIndices用于获取受影响的节点的列表。 
            一个例外是一个treeNodesChanged事件,用于标识根,在这种情况下,这将返回根, getChildIndices将返回null。 
TreePath.getLastPathComponent() 
           public Object[] getPath()
public Object[] getChildren()
getPath在由指定的位置getChildIndices 。 
           如果这是一个删除事件,返回的对象不再是父节点的子节点。 
          getPath() , 
            getChildIndices() 
           public int[] getChildIndices()
int指定的 
            int项的索引位置的数组 
            int 
           public String toString()
toString在 
            EventObject 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.