private static @Nullable TreePath getAnchor(@Nullable JTree tree) {
    if (tree == null || SINGLE_TREE_SELECTION == tree.getSelectionModel().getSelectionMode()) return null; // unexpected usage
    TreePath anchor = tree.getAnchorSelectionPath(); // search for visible path
    while (anchor != null && tree.getRowForPath(anchor) < 0) anchor = anchor.getParentPath();
    return anchor;
  }
private static @Nullable TreePath getAnchor(@Nullable JTree tree)