/** Opens the SubMenu */
    public void menuKeyTyped(MenuKeyEvent e) {
      if (!crossMenuMnemonic) {
        JPopupMenu pm = getActivePopupMenu();
        if (pm != null && pm != menuItem.getParent()) {
          return;
        }
      }

      int key = menuItem.getMnemonic();
      if (key == 0) return;
      MenuElement path[] = e.getPath();
      if (lower((char) key) == lower(e.getKeyChar())) {
        JPopupMenu popupMenu = ((JMenu) menuItem).getPopupMenu();
        MenuElement sub[] = popupMenu.getSubElements();
        if (sub.length > 0) {
          MenuSelectionManager manager = e.getMenuSelectionManager();
          MenuElement newPath[] = new MenuElement[path.length + 2];
          System.arraycopy(path, 0, newPath, 0, path.length);
          newPath[path.length] = popupMenu;
          newPath[path.length + 1] = sub[0];
          manager.setSelectedPath(newPath);
        }
        e.consume();
      }
    }
    /**
     * Handles the mnemonics for the menu items. Will also handle duplicate mnemonics. Perhaps this
     * should be moved into BasicPopupMenuUI. See 4670831
     */
    public void menuKeyPressed(MenuKeyEvent e) {
      // Handle the case for Escape or Enter...
      char keyChar = e.getKeyChar();
      if (!Character.isLetterOrDigit(keyChar)) return;

      MenuSelectionManager manager = e.getMenuSelectionManager();
      MenuElement selectedPath[] = manager.getSelectedPath();

      for (int i = selectedPath.length - 1; i >= 0; i--) {
        if (selectedPath[i] == menuItem) {
          JPopupMenu popupMenu = ((JMenu) menuItem).getPopupMenu();
          MenuElement items[] = popupMenu.getSubElements();

          int index = -1;

          for (int j = 0; j < items.length; j++) {
            int key = ((JMenuItem) items[j]).getMnemonic();
            if (Character.toLowerCase((char) key) == Character.toLowerCase(keyChar)) {
              index = j;
              break;
            }
          }

          if (index != -1) {
            // Invoke the menu action
            JMenuItem item = (JMenuItem) items[index];
            if (!(item instanceof JMenu)) {
              // Let Submenus be handled by menuKeyTyped
              manager.clearSelectedPath();
              item.doClick();
            }
          }

          e.consume();
          return;
        }
      }
    }