Java Swing Menu createMenu(String label, Object... objects)

Here you can find the source of createMenu(String label, Object... objects)

Description

create Menu

License

Open Source License

Declaration

static JMenu createMenu(String label, Object... objects) 

Method Source Code

//package com.java2s;
/*/*w  w w .j  a v  a2s.  co  m*/
Formulae - Free Expressions
Copyright (C) Laurence R. Ugalde - laurence@formulae.org
formulae.org
    
This file is part of Formulae front-end "Desktop".
    
Formulae Desktop is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
Formulae Desktop 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 General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Formulae Desktop. If not, see <http://www.gnu.org/licenses/>.
*/

import javax.swing.JMenu;
import javax.swing.Action;

import javax.swing.JMenuItem;

public class Main {
    static JMenu createMenu(String label, Object... objects) {
        return createMenu(label, -1, objects);
    }

    static JMenu createMenu(String label, int mnemonic, Object... objects) {
        JMenu menu = new JMenu(label);

        if (mnemonic >= 0) {
            menu.setMnemonic(mnemonic);
        }

        for (Object o : objects) {
            if (o == null) {
                menu.addSeparator();
            } else if (o instanceof Action) {
                JMenuItem menuItem = new JMenuItem((Action) o);
                menu.setToolTipText(null);
                menu.add(menuItem);
            } else if (o instanceof JMenuItem) {
                menu.add((JMenuItem) o);
            } else {
                throw new IllegalArgumentException();
            }
        }

        return menu;
    }
}

Related

  1. createMenu(final String label, final String mnemonic, final String accessibleDescription)
  2. createMenu(final String name, final int mnemonic)
  3. createMenu(final String text)
  4. createMenu(final String text, final char mnemonic)
  5. createMenu(String label, int mnemonic, String description)
  6. createMenu(String name, Object[] item, int[] accelerator, ActionListener listener)
  7. createMenu(String text)
  8. createMenuKeyMask(final int aKeyStroke, final int... aMasks)
  9. enableMenu(JTextComponent text)