MenuSelectionManager manager = MenuSelectionManager.defaultManager(); manager.setSelectedPath(e.getPath());
if (menuItem.isEnabled()) { MenuSelectionManager manager = e.getMenuSelectionManager(); MenuElement path[] = e.getPath();  Point p = e.getPoint(); if(p.x >= 0 && p.x < menuItem.getWidth() && p.y >= 0 && p.y < menuItem.getHeight()) { JMenu menu = (JMenu) menuItem; MenuElement[] selectedPath = manager.getSelectedPath(); if(! (selectedPath.length > 0 && selectedPath[selectedPath.length-1] == menu.getPopupMenu())) { if(menu.isTopLevelMenu() || menu.getDelay() == 0 || e.getID() == MouseEvent.MOUSE_DRAGGED) { MenuElement[] newPath = new MenuElement[path.length + 1]; System.arraycopy(path, 0, newPath, 0, path.length); newPath[path.length] = menu.getPopupMenu(); manager.setSelectedPath(newPath); } else { manager.setSelectedPath(path); setupPostTimer(menu); } } } else if (e.getID() == MouseEvent.MOUSE_RELEASED) { Component comp = manager.componentForPoint(e.getComponent(), e.getPoint()); if (comp == null) manager.clearSelectedPath(); } }
    public void menuDragMouseDragged(MenuDragMouseEvent e)    {      MenuSelectionManager manager = MenuSelectionManager.defaultManager();      manager.setSelectedPath(e.getPath());    }