2013-10-04 38 views
0

我有一個JTree節點數組和另一個自定義對象的相應數組。影響JLabel的JTree

我想要什麼: 當JTree的節點被選中時,相應對象的字段(其陣列中相同索引的對象作爲節點數組中選定節點的索引)填充JLabels。

我在哪裏卡住了: TreeSelectionListener。我不知道如何獲得其陣列中所選節點的索引。

有沒有可能?有任何想法嗎?

回答

1

自己解決。雖然很簡單,但我以前沒有想到它。我猜2 AM並不是編程的最佳時機。絕招:

int index = Arrays.asList(nodesArray).indexOf(tree.getLastSelectedPathComponent());