boolean (JTree tree, int dir) { final TreePath[] selectionPaths = tree.getSelectionPaths(); if (selectionPaths != null) { DefaultMutableTreeNode parent = null; for (TreePath treePath : selectionPaths) if (treePath.getLastPathComponent() != null) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath.getLastPathComponent(); if (parent == null) { parent = (DefaultMutableTreeNode)node.getParent(); } if (parent == null || parent != node.getParent()) { return false; } if (dir > 0) { if (parent.getIndex(node) == parent.getChildCount() - 1) { return false; } } else { if (parent.getIndex(node) == 0) { return false; } } } return true; } return false; }