[英]jtree couldnt get index of specific node
我有jTree(例如):
-paper
-coated
-glossy
-hummermill
-quatro
-springhill
-matte
當我選擇springhill我得到5的索引,但我不想從根(紙)(包括父母和光澤之外的其他節點)計數,我想從hummermill開始計數所以我試圖獲得2的索引。
我使用了tree.getLeadSelectionRow()
並獲取了5的int值; 我也使用node.getIndex(node)
但在這里我沒有得到任何正常的(0,3,-1)。 我嘗試了節點和樹的所有方法的所有變化,並找不到任何有用的東西。 請求幫助!
您必須從其父節點中找到節點的索引
DefaultMutableTreeNode node=(DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
System.out.println(node.getParent().getIndex(node));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.