if (! m.isComponentPartOfCurrentMenu(target))
if (m.getSelectedPath().length > 0 && ! m.isComponentPartOfCurrentMenu(target) && (((JComponent)target).getClientProperty(DONT_CANCEL_POPUP) == null || !((JComponent)target).getClientProperty(DONT_CANCEL_POPUP).equals(Boolean.TRUE))) {
    private void mousePressed(MouseEvent ev)    {      // Autoclose all menus managed by the MenuSelectionManager.      MenuSelectionManager m = MenuSelectionManager.defaultManager();      Component target = ev.getComponent();      if (target instanceof Container)        target = ((Container) target).findComponentAt(ev.getPoint());      if (! m.isComponentPartOfCurrentMenu(target))        m.clearSelectedPath();    }