| 
 | JavaTM 2 Platform Standard Ed. 6 | |||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
public interface TreeModel
JTree 所使用的模型。
 
JTree 及其相關類別大量使用了 TreePath,以標識 TreeModel 中的節點。如果 TreeModel 返回相同的物件(使用 equals 比較同一父節點下的兩個不同索引的節點),那麼產生的 TreePath 物件也被認為是相等的。某些實作可以假定,如果兩個 TreePath 相等,則它們標識的節點也相等。如果不能滿足此條件,則可能導致繪製問題和其他奇怪的問題。換句話說,如果對給定父節點調用 getChild 返回相同的 Object(由 equals 確定),則可能出現問題,建議您不要執行此操作。
 
類似地,JTree 及其相關類別將 TreePath 置於 Map 中。因此,如果兩次請求一個節點,則其返回值必須相等(使用 equals 方法)並且具有相同的 hashCode。
 
有關階層樹模型的更多資訊(包括自定義實作的範例),請參閱 The Java Tutorial 中的 How to Use Trees。
TreePath| 方法摘要 | |
|---|---|
|  void | addTreeModelListener(TreeModelListener l)為階層樹更改後發佈的 TreeModelEvent添加偵聽器。 | 
|  Object | getChild(Object parent,
         int index)返回父節點的子陣列中索引 index位置的parent的子節點。 | 
|  int | getChildCount(Object parent)返回 parent的子節點數。 | 
|  int | getIndexOfChild(Object parent,
                Object child)返回父節點中子節點的索引。 | 
|  Object | getRoot()返回階層樹的根。 | 
|  boolean | isLeaf(Object node)如果 node為葉節點,則返回true。 | 
|  void | removeTreeModelListener(TreeModelListener l)移除以前通過 addTreeModelListener添加的偵聽器。 | 
|  void | valueForPathChanged(TreePath path,
                    Object newValue)使用者已將 path標識的項的值更改為newValue時,進行通知。 | 
| 方法詳細資訊 | 
|---|
Object getRoot()
null。
Object getChild(Object parent,
                int index)
index 位置的 parent 的子節點。parent 必須是以前從此資料源獲取的節點。如果 index 是 parent 的一個有效索引(即:index >= 0 && index < getChildCount(parent)),則此方法不應返回 null。
parent - 從此資料源獲取的階層樹中的節點
index 位置的 parent 的子節點int getChildCount(Object parent)
parent 的子節點數。如果該節點為葉節點,或者它沒有子節點,則返回 0。parent 必須是以前從此資料源獲取的節點。
parent - 從此資料源獲取的階層樹中的節點
parent 的子節點數boolean isLeaf(Object node)
node 為葉節點,則返回 true。即使 node 沒有子節點,此方法也可能返回 false。例如,檔案系統中的目錄可以不包含任何檔案;表示該目錄的節點不是葉節點,但是它也沒有任何子節點。
node - 從此資料源獲取的階層樹中的節點
node 為葉節點,則返回 true
void valueForPathChanged(TreePath path,
                         Object newValue)
path 標識的項的值更改為 newValue 時,進行通知。如果 newValue 表示一個真實的新值,則該模型應發佈一個 treeNodesChanged 事件。
path - 使用者已更改的節點的路徑newValue - TreeCellEditor 的新值
int getIndexOfChild(Object parent,
                    Object child)
parent 或 child 為 null,則返回 -1。如果 parent 或 child 不屬於此階層樹模型,則返回 -1。
parent - 從此資料源獲取的階層樹中的節點child - 相關的節點
child 或 parent 為 null,或不屬於此階層樹模型,則返回 -1void addTreeModelListener(TreeModelListener l)
TreeModelEvent 添加偵聽器。
l - 要添加的偵聽器removeTreeModelListener(javax.swing.event.TreeModelListener)void removeTreeModelListener(TreeModelListener l)
addTreeModelListener 添加的偵聽器。
l - 要移除的偵聽器addTreeModelListener(javax.swing.event.TreeModelListener)| 
 | JavaTM 2 Platform Standard Ed. 6 | |||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。