boolean (final KeyEvent e) { final boolean closeRequest = AbstractPopup.isCloseRequest(e); JBPopup popup = closeRequest ? findPopup() : getFocusedPopup(); if (popup == null) return false; Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); if (window instanceof Dialog && ((Dialog)window).isModal()) { if (!SwingUtilities.isDescendingFrom(popup.getContent(), window)) return false; } return popup.dispatchKeyEvent(e); }