public void mousePressed(MouseEvent e) {
      MenuSelectionManager manager = MenuSelectionManager.defaultManager();
      JMenu menu = (JMenu) menuItem;
      manager.processMouseEvent(e);

      // Menu should be displayed when the menu is pressed only if
      // it is top-level menu
      if (menu.isTopLevelMenu()) {
        if (menu.getPopupMenu().isVisible())
          // If menu is visible and menu button was pressed..
          // then need to cancel the menu
          manager.clearSelectedPath();
        else {
          // Display the menu
          int x = 0;
          int y = menu.getHeight();

          manager.setSelectedPath(getPath());

          JMenuBar mb = (JMenuBar) menu.getParent();

          // set selectedIndex of the selectionModel of a menuBar
          mb.getSelectionModel().setSelectedIndex(mb.getComponentIndex(menu));
        }
      }
    }