boolean (@NotNull AbstractPopup popup, @NotNull MouseEvent mouseEvent) { if (popup.isDisposed()) { return false; } int modifiers = mouseEvent.getModifiersEx() & (InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK | InputEvent.META_DOWN_MASK); if (mouseEvent.getButton() != MouseEvent.BUTTON1 || modifiers != 0) { // on right mouse in most cases we can customize corresponding toolbar return false; } Component toggleButton = PopupUtil.getPopupToggleComponent(popup); Component c = mouseEvent.getComponent(); if (toggleButton == null || c == null) { return false; } Point pointRelativeToButton = SwingUtilities.convertPoint(c, mouseEvent.getX(), mouseEvent.getY(), toggleButton); return toggleButton.contains(pointRelativeToButton); }