if (invoker != null && !(invoker instanceof JMenu))
if (invoker != null) { if (!(invoker instanceof JMenu)) { MenuElement[] menuEls; if (getSubElements().length > 0) { menuEls = new MenuElement[2]; menuEls[0] = this; menuEls[1] = getSubElements()[0]; } else { menuEls = new MenuElement[1]; menuEls[0] = this; } MenuSelectionManager.defaultManager().setSelectedPath(menuEls); } else
  public void setVisible(final boolean visible)  {    // Hook up this call so that it gets executed on the event thread in order    // to avoid synchronization problems when calling the layout manager.    if (! SwingUtilities.isEventDispatchThread())      {        SwingUtilities.invokeLater(new Runnable()          {            public void run()            {              setVisible(visible);            }          });      }    if (visible == isVisible())      return;    boolean old = isVisible();    this.visible = visible;    if (old != isVisible())      {        if (visible)          {            if (invoker != null && !(invoker instanceof JMenu))              {                MenuElement[] menuEls;                if (getSubElements().length > 0)                  {                    menuEls = new MenuElement[2];                    menuEls[0] = this;                    menuEls[1] = getSubElements()[0];                }                else                  {                    menuEls = new MenuElement[1];                    menuEls[0] = this;                  }                MenuSelectionManager.defaultManager().setSelectedPath(menuEls);              }            firePopupMenuWillBecomeVisible();            PopupFactory pf = PopupFactory.getSharedInstance();            pack();            popup = pf.getPopup(invoker, this, popupLocationX, popupLocationY);            popup.show();          }        else          {            getSelectionModel().clearSelection();            firePopupMenuWillBecomeInvisible();            popup.hide();          }        firePropertyChange("visible", old, isVisible());      }  }