void () { if (isPopupShowing()) return; final ActionGroup group; if (myOrientation == SwingConstants.HORIZONTAL) { group = myActionGroup; } else { final DefaultActionGroup outside = new DefaultActionGroup(); for (int i = myFirstOutsideIndex; i < myVisibleActions.size(); i++) { outside.add(myVisibleActions.get(i)); } group = outside; } PopupToolbar popupToolbar = new PopupToolbar(myPlace, group, true, this) { @Override protected void onOtherActionPerformed() { hidePopup(); } @Override protected @NotNull DataContext getDataContext() { return ActionToolbarImpl.this.getDataContext(); } }; popupToolbar.setLayoutPolicy(NOWRAP_LAYOUT_POLICY); Point location; if (myOrientation == SwingConstants.HORIZONTAL) { location = getLocationOnScreen(); ToolWindow toolWindow = DataManager.getInstance().getDataContext(this).getData(PlatformDataKeys.TOOL_WINDOW); if (toolWindow != null && toolWindow.getAnchor() == ToolWindowAnchor.RIGHT) { int rightXOnScreen = location.x + getWidth(); int toolbarPreferredWidth = popupToolbar.getPreferredSize().width; location.x = rightXOnScreen - toolbarPreferredWidth; } } else { location = getLocationOnScreen(); location.y = location.y + getHeight() - popupToolbar.getPreferredSize().height; } ActionManagerEx actionManager = ActionManagerEx.getInstanceEx(); final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(popupToolbar, null); builder.setResizable(false) .setMovable(true) // fit the screen automatically .setFocusable(false) // do not steal focus on showing, and don't close on IDE frame gaining focus (see AbstractPopup.isCancelNeeded) .setMayBeParent(true) .setTitle(null) .setCancelOnClickOutside(true) .setCancelOnOtherWindowOpen(true) .setCancelCallback(() -> { final boolean toClose = actionManager.isActionPopupStackEmpty(); if (toClose) { myUpdater.updateActions(false, true, false); } return toClose; }) .setCancelOnMouseOutCallback(event -> { Window window = ComponentUtil.getWindow(popupToolbar); if (window != null && Window.Type.POPUP == window.getType()) { Component parent = UIUtil.uiParents(event.getComponent(), false).find(window::equals); if (parent != null) return false; // mouse over a child popup } return myAutoPopupRec != null && actionManager.isActionPopupStackEmpty() && !new RelativeRectangle(this, myAutoPopupRec).contains(new RelativePoint(event)); }); builder.addListener(new JBPopupListener() { @Override public void onClosed(@NotNull LightweightWindowEvent event) { processClosed(); } }); myPopup = builder.createPopup(); Disposer.register(myPopup, popupToolbar); myPopup.showInScreenCoordinates(this, location); Window window = SwingUtilities.getWindowAncestor(this); if (window == null) { return; } ComponentListener componentAdapter = new ComponentAdapter() { @Override public void componentResized(final ComponentEvent e) { hidePopup(); } @Override public void componentMoved(final ComponentEvent e) { hidePopup(); } @Override public void componentShown(final ComponentEvent e) { hidePopup(); } @Override public void componentHidden(final ComponentEvent e) { hidePopup(); } }; window.addComponentListener(componentAdapter); Disposer.register(popupToolbar, () -> window.removeComponentListener(componentAdapter)); }