boolean topLevelMenu = (popupMenu.getInvoker() instanceof JMenu) && ((JMenu) popupMenu.getInvoker()).isTopLevelMenu();  if ((topLevelMenu || !(popupMenu.getInvoker() instanceof MenuElement)) && rootContainer instanceof RootPaneContainer) { RootPaneContainer rpContainer = (RootPaneContainer) rootContainer;   Container glassPane = (Container) rpContainer.getGlassPane(); glassPane.setVisible(false); glassPane.removeMouseListener(mouseInputListener); mouseInputListener = null; }
    public void popupMenuWillBecomeInvisible(PopupMenuEvent event)    {      // remove listener that listens to component events fired       // by the top - level window that this popup belongs to.      Component invoker = popupMenu.getInvoker();      Component rootContainer = SwingUtilities.getRoot(invoker);      if (rootContainer != null)        {          rootContainer.removeComponentListener(topWindowListener);          // If this popup menu is the last popup menu visible on the screen,          // then      // stop interrupting mouse events in the glass pane before hiding this       // last popup menu.      boolean topLevelMenu = (popupMenu.getInvoker() instanceof JMenu)                                 && ((JMenu) popupMenu.getInvoker()).isTopLevelMenu();          if ((topLevelMenu || !(popupMenu.getInvoker() instanceof MenuElement))              && rootContainer instanceof RootPaneContainer)        {              RootPaneContainer rpContainer = (RootPaneContainer) rootContainer;          // set glass pane not to interrupt mouse events and remove	  // mouseInputListener              Container glassPane = (Container) rpContainer.getGlassPane();	  glassPane.setVisible(false);	  glassPane.removeMouseListener(mouseInputListener);	  mouseInputListener = null;        }    }    }