Here you can find the source of createMenu(String label, Object... objects)
static JMenu createMenu(String label, Object... objects)
//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; } }