public static int computeIndexInParent ( Object nodeObject ) { if ( nodeObject instanceof DefaultMutableTreeNode ) { DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) nodeObject ; TreeNode parent = node . getParent ( ) ; if ( parent == null ) { return - 1 ; } int childCount = parent . getChildCount ( ) ; for ( int i = 0 ; i < childCount ; i ++ ) { TreeNode child = parent . getChildAt ( i ) ; if ( child == nodeObject ) { return i ; } } } return - 1 ; }
Computes the index that the given node has in its parent node . Returns - 1 if the given node does not have a parent or the node is not a DefaultMutableTreeNode .