code: private void prepareMenu(Container menu, Component component, int x, int y)
      {
          int n = menu.getComponentCount();
          for (int i=0; i<n; i++)
          {
              Component menuComponent = popupMenu.getComponent(i);
              if (menuComponent instanceof JMenu)
              {
                  JMenu subMenu = (JMenu)menuComponent;
                  prepareMenu(subMenu, component, x, y);
              }
              if (menuComponent instanceof AbstractButton)
              {
                  AbstractButton abstractButton = (AbstractButton)menuComponent;
                  Action action = abstractButton.getAction();
                  if (action != null && action instanceof LocationBasedAction)
                  {
                      LocationBasedAction locationBasedAction = 
                          (LocationBasedAction)action;
                      locationBasedAction.prepareShow(component, x, y);
                  }
              }
          }
      }
docs: Prepare the given menu recursively with the given parameters
  
  @param menu The menu
  @param component The component
  @param x The x-coordinate
  @param y THe y-coordinate