Java JPopupMenu makePopupMenu(JPopupMenu menu, List menuItems)

Here you can find the source of makePopupMenu(JPopupMenu menu, List menuItems)

Description

Create a JPopupMenu and add the menus contained with the menus list If no menus then return null.

License

Open Source License

Parameter

Parameter Description
menu The menu
menuItems List of either, JMenu, JMenuItem or MENU_SEPARATOR

Return

The given menu

Declaration

public static JPopupMenu makePopupMenu(JPopupMenu menu, List menuItems) 

Method Source Code

//package com.java2s;
/*/*from  w  ww. j  a  va  2 s  .c o m*/
 * $Id: GuiUtils.java,v 1.317 2007/08/10 14:26:33 jeffmc Exp $
 *
 * Copyright  1997-2016 Unidata Program Center/University Corporation for
 * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307,
 * support@unidata.ucar.edu.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.util.List;
import javax.swing.*;

public class Main {
    /** Separator flag */
    public static final String MENU_SEPARATOR = "separator";

    /**
     *  Create a JPopupMenu and add the menus contained with the menus list
     *  If no menus then return null.
     *
     * @param menu The menu
     * @param menuItems List of either, JMenu, JMenuItem or MENU_SEPARATOR
     * @return The given menu
     */
    public static JPopupMenu makePopupMenu(JPopupMenu menu, List menuItems) {
        if ((menuItems == null) || (menuItems.size() == 0)) {
            return null;
        }
        for (int i = 0; i < menuItems.size(); i++) {
            Object o = menuItems.get(i);
            if (o.toString().equals(MENU_SEPARATOR)) {
                menu.addSeparator();
            } else if (o instanceof JMenuItem) {
                menu.add((JMenuItem) o);
            } else if (o instanceof JMenu) {
                menu.add((JMenu) o);
            }
        }
        return menu;
    }

    /**
     *  Create a JPopupMenu and add the menus contained with the menus list
     *  If no menus then return null.
     *
     * @param menuItems List of either, JMenu, JMenuItem or MENU_SEPARATOR
     * @return The new popup menu
     */
    public static JPopupMenu makePopupMenu(List menuItems) {
        return makePopupMenu(new JPopupMenu(), menuItems);
    }
}

Related

  1. getPopupMenu()
  2. getPopupMenuShowPoint(JPopupMenu popup, int x, int y)
  3. insertSeparatorIfNeeded(JPopupMenu popupMenu, int position)
  4. installPopupMenuColorAndFonts(final JComponent contentPane)
  5. isPopupMenuSeparator(Component component)
  6. maybeShowPopup(MouseEvent e, JPopupMenu menu, JComponent parent)
  7. optimizeSeparators(JPopupMenu menu)
  8. positionPopup(Component component, JPopupMenu jpm, int xCoord, int yCoord)
  9. positionPopupMenu(final JPopupMenu popupMenu, final MouseEvent event, final Rectangle rectangle, final int dividerlocation)