PopupHandler (@NotNull JComponent component, @NotNull String place, @Nullable ActionManager actionManager, @Nullable PopupMenuListener menuListener, @NotNull Function<? super ActionManager, ? extends ActionGroup> group) { if (ApplicationManager.getApplication() == null) { return EMPTY_HANDLER; } PopupHandler popupHandler = new PopupHandler() { @Override public void invokePopup(Component comp, int x, int y) { ActionManager manager = actionManager == null ? ActionManager.getInstance() : actionManager; ActionGroup actionGroup = group.apply(manager); if (actionGroup == null) return; ActionPopupMenu popupMenu = manager.createActionPopupMenu(place, actionGroup); popupMenu.setTargetComponent(component); JPopupMenu menu = popupMenu.getComponent(); if (menuListener != null) { menu.addPopupMenuListener(menuListener); } menu.show(comp, x, y); } }; component.addMouseListener(popupHandler); return popupHandler; }