void (@NotNull JBPopup hint) { myHint = hint; FocusListener focusAdapter = new FocusAdapter() { @Override public void focusLost(FocusEvent e) { Component previouslyFocused = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject); if (previouslyFocused != DocumentationHintEditorPane.this) { hint.cancel(); } } }; addFocusListener(focusAdapter); Disposer.register(hint, () -> { myHint = null; removeFocusListener(focusAdapter); }); }