AbstractTreeNode (final Object element) { final TreePath[] selectionPaths = getTree().getSelectionPaths(); if (selectionPaths == null) { return null; } for (TreePath selectionPath : selectionPaths) { Object selected = selectionPath.getLastPathComponent(); if (selected instanceof DefaultMutableTreeNode && elementIsEqualTo(selected, element)) { Object userObject = ((DefaultMutableTreeNode)selected).getUserObject(); if (userObject instanceof AbstractTreeNode) return (AbstractTreeNode)userObject; } } return null; }