int (TreePath path) { Object[] nodes = path.getPath(); for (int i = 1; i < nodes.length; i++) { TreeNode node = (TreeNode) nodes[i]; if (node.getParent() == null) return i - 1; } return nodes.length - 1; }