Search code examples
javaswingjtree

Get index of selected node in a JTree


How can I get the index of a selected node in its parent. For example D should be index 3 in root. I tried with jTree.getSelectionPath() but it doesn't show the index

root
     A
     B
     C
        a
     D
        a
        b
        c
     E

Solution

  • JTree has the methods

    public int[] getSelectionRows()
    public int getMinSelectionRow()
    public int getMaxSelectionRow()