public interface TreeModel
JTree.
JTree и его связанные классы делают широкое применение TreePaths для indentifying узлов в TreeModel. Если a TreeModel возвращает тот же самый объект, как сравнено equals, в двух различных индексах под тем же самым родителем чем получающееся TreePath объекты будут считать равными также. Некоторые реализации могут принять это если два TreePaths равны, они идентифицируют тот же самый узел. Если это условие не соблюдают, крася проблемы, и другие причуды могут закончиться. Другими словами, если getChild поскольку данный родитель возвращает тот же самый Объект (как определено equals) проблемы могут закончиться, и рекомендуется, чтобы Вы избежали делать это.
Так же JTree и его связанное место классов TreePaths в Maps. Как таковой, если узел требуют дважды, возвращаемые значения должны быть равными (использование equals метод), и имеют то же самое hashCode.
Для дополнительной информации о древовидных моделях, включая пример пользовательской реализации, видят в Учебном руководстве по Java.
TreePath| Модификатор и Тип | Метод и Описание |
|---|---|
void |
addTreeModelListener(TreeModelListener l)
Добавляет слушатель для
TreeModelEvent отправленный после древовидных изменений. |
Объект |
getChild(Object parent, int index)
Возвращает дочерний элемент
parent в индексируют index в дочернем массиве родителя. |
int |
getChildCount(Object parent)
Возвращает число дочерних элементов
parent. |
int |
getIndexOfChild(Object parent, Object child)
Возвращает индексирование дочернего элемента в родителе.
|
Объект |
getRoot()
Возвращает корень дерева.
|
boolean |
isLeaf(Object node)
Возвраты
true если node лист. |
void |
removeTreeModelListener(TreeModelListener l)
Удаляет слушателя, ранее добавленного с
addTreeModelListener. |
void |
valueForPathChanged(TreePath path, Object newValue)
Переданный, когда пользователь изменил значение для элемента, идентифицированного
path к newValue. |
Object getRoot()
null только если у дерева нет никаких узлов.Object getChild(Object parent, int index)
parent в индексируют index в дочернем массиве родителя. parent должен быть узел, ранее полученный из этого источника данных. Это не должно возвратиться null если index допустимое, индексируют для parent (который является index >= 0 && index < getChildCount(parent)).parent - a node in the tree, obtained from this data sourceparent at index indexint getChildCount(Object parent)
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 sourceparentboolean isLeaf(Object node)
true if node is a leaf. It is possible for this method to return false even if node has no children. A directory in a filesystem, for example, may contain no files; the node representing the directory is not a leaf, but it also has no children.node - a node in the tree, obtained from this data sourcenode is a leafvoid valueForPathChanged(TreePath path, Object newValue)
path to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.path - path to the node that the user has alterednewValue - the new value from the TreeCellEditorint getIndexOfChild(Object parent, Object child)
parent or child is null, returns -1. If either parent or child don't belong to this tree model, returns -1.parent - a node in the tree, obtained from this data sourcechild - the node we are interested inchild or parent are null or don't belong to this tree modelvoid addTreeModelListener(TreeModelListener l)
TreeModelEvent posted after the tree changes.l - the listener to addremoveTreeModelListener(javax.swing.event.TreeModelListener)void removeTreeModelListener(TreeModelListener l)
addTreeModelListener.l - the listener to removeaddTreeModelListener(javax.swing.event.TreeModelListener)
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, 2013, Oracle and/or its affiliates. All rights reserved.
DRAFT ea-b92