if (selection.length == 0) return;
  public void processKeyEvent(KeyEvent e)  {    MenuElement[] selection = (MenuElement[])                    selectedPath.toArray(new MenuElement[selectedPath.size()]);    MenuElement[] path;    for (int index = selection.length - 1; index >= 0; index--)      {        MenuElement el = selection[index];        // This method's main purpose is to forward key events to the        // relevant menu items, so that they can act in response to their        // mnemonics beeing typed. So we also need to forward the key event        // to all the subelements of the currently selected menu elements        // in the path.        MenuElement[] subEls = el.getSubElements();        path = null;        for (int subIndex = 0; subIndex < subEls.length; subIndex++)          {            MenuElement sub = subEls[subIndex];            // Skip elements that are not showing or not enabled.            if (sub == null || ! sub.getComponent().isShowing()                || ! sub.getComponent().isEnabled())              {                continue;              }            if (path == null)              {                path = new MenuElement[index + 2];                System.arraycopy(selection, 0, path, 0, index + 1);              }            path[index + 1] = sub;            sub.processKeyEvent(e, path, this);            if (e.isConsumed())              break;          }        if (e.isConsumed())          break;      }    // Dispatch to first element in selection if it hasn't been consumed.    if (! e.isConsumed())      {        path = new MenuElement[1];        path[0] = selection[0];        path[0].processKeyEvent(e, path, this);      }  }