int (@NotNull Object element) { Set<Object> selection = getSelectedElements(); if (selection.contains(element)) { TreePath[] paths = getTree().getSelectionPaths(); for (TreePath each : paths) { if (element.equals(getElementFor(each.getLastPathComponent()))) { return getTree().getRowForPath(each); } } return -1; } Object anchor = TreeAnchorizer.getService().createAnchor(element); Object o = isNodeNull(anchor) ? null : myElementToNodeMap.get(anchor); TreeAnchorizer.getService().freeAnchor(anchor); if (o instanceof List) { TreePath[] paths = getTree().getSelectionPaths(); if (paths != null && paths.length > 0) { Set<DefaultMutableTreeNode> selectedNodes = new HashSet<>(); for (TreePath eachPAth : paths) { if (eachPAth.getLastPathComponent() instanceof DefaultMutableTreeNode) { selectedNodes.add((DefaultMutableTreeNode)eachPAth.getLastPathComponent()); } } //noinspection unchecked for (DefaultMutableTreeNode eachNode : (List<DefaultMutableTreeNode>)o) { while (eachNode != null) { if (selectedNodes.contains(eachNode)) { return getTree().getRowForPath(getPathFor(eachNode)); } eachNode = (DefaultMutableTreeNode)eachNode.getParent(); } } } } return -1; }