TreePath () { int aliveIndex = findLowestAliveNodeIndex(mySelectionPath); if (aliveIndex == mySelectionPath.getPathCount() - 1) return mySelectionPath; TreeNode aliveAncestor = (TreeNode) mySelectionPath.getPathComponent(aliveIndex); TreePath newSelection = TreeUtil.getPathFromRoot(aliveAncestor); int childrenLeft = aliveAncestor.getChildCount(); if (childrenLeft != 0) { int newSelectedChildIndex = Math.min(myIndicies[aliveIndex + 1], childrenLeft - 1); newSelection = newSelection.pathByAddingChild(aliveAncestor.getChildAt(newSelectedChildIndex)); } return newSelection; }