JBPopup (final Tree tree) { if (myPopup != null) { myPopup.cancel(); } tree.getModel().addTreeModelListener(createTreeModelListener(tree)); FocusListener focusListener = createTreeFocusListener(); tree.addFocusListener(focusListener); JComponent popupContent = createPopupContent(tree); setContent(popupContent, getToolbarActions(), ACTION_PLACE, tree); myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(myContent, tree) .setRequestFocus(true) .setResizable(true) .setModalContext(false) .setMovable(true) .setDimensionServiceKey(myProject, DIMENSION_SERVICE_KEY, false) .setMayBeParent(true) .setCancelOnOtherWindowOpen(true) .setCancelKeyEnabled(false) .setKeyEventHandler(event -> { if (!mySetValueModeEnabled && event.getKeyCode() == KeyEvent.VK_F2) { enableSetValueMode(); } else if (AbstractPopup.isCloseRequest(event)) { // Do not process a close request if the tree shows a speed search popup or 'set value' action is in process SpeedSearchBase speedSearch = ((SpeedSearchBase)SpeedSearchSupply.getSupply(tree)); if (speedSearch != null && speedSearch.isPopupActive()) { speedSearch.hidePopup(); return true; } else if (IdeFocusManager.getInstance(myProject).getFocusOwner() == tree) { myPopup.cancel(); return true; } return false; } return false; }) .addListener(new JBPopupListener() { @Override public void onClosed(@NotNull LightweightWindowEvent event) { tree.removeFocusListener(focusListener); if (myHideRunnable != null) { myHideRunnable.run(); } } }) .setCancelCallback(() -> { Window parent = SwingUtilities.getWindowAncestor(tree); if (parent != null) { for (Window child : parent.getOwnedWindows()) { if (child.isShowing()) { return false; } } } return true; }) .createPopup(); registerTreeDisposable(myPopup, tree); //Editor may be disposed before later invokator process this action if (myEditor.isDisposed()) { myPopup.cancel(); return null; } myPopup.setSize(new Dimension(0, 0)); setAutoResizeUntilToolbarNotFull(() -> updateDebugPopupBounds(tree, myToolbar, myPopup, false), myPopup); myPopup.show(new RelativePoint(myEditor.getContentComponent(), myPoint)); setAutoResize(tree, myToolbar, myPopup); return myPopup; }