void (JTree tree) { tree.setComponentPopupMenu(new JPopupMenu() { private @Nullable Collection<String> names; @Override public void show(Component invoker, int x, int y) { names = null; if (invoker != tree) return; TreePath path = tree.getClosestPathForLocation(x, y); names = getPathNames(extractNode(path)); if (names.isEmpty()) { return; } Rectangle bounds = tree.getPathBounds(path); if (bounds == null || bounds.y > y) return; bounds.y += bounds.height; if (bounds.y < y) return; DefaultActionGroup group = new DefaultActionGroup(); for (Action action : CopySettingsPathAction.createSwingActions(() -> names)) { group.add(ActionUtil.createActionFromSwingAction(action)); } JPopupMenu popup = ActionManager.getInstance().createActionPopupMenu("settings", group).getComponent(); popup.show(invoker, x, bounds.y); } }); }