0

I have an array of JTree nodes and a corresponding array of another custom object.

What I want: When a node of the JTree gets selected, fields of the corresponding object (object of the same index in its array as the index of the selected node in the nodes array) to fill JLabels.

Where am I stuck: The TreeSelectionListener. I have no idea how to get the index of the chosen node in its array.

Is it possible at all? Any ideas?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
ngr900
  • 452
  • 4
  • 12

1 Answers1

1

Solved it myself. Pretty straightforward though, shame I didn't think of it before. I guess 2 AM is not the perfect time for programming. The line that did the trick:

int index = Arrays.asList(nodesArray).indexOf(tree.getLastSelectedPathComponent());
ngr900
  • 452
  • 4
  • 12