void (MouseEvent e) { super.handlePopup(e); JPopupMenu popup = myTabs.getActivePopup(); if (popup != null) { popup.addPopupMenuListener(new PopupMenuListenerAdapter() { @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { handle(); } @Override public void popupMenuCanceled(PopupMenuEvent e) { handle(); } private void handle() { popup.removePopupMenuListener(this); myActionPanel.setVisible(!showCloseActionOnHover() || isHovered()); } }); } }