Here you can find the source of createMenu(String name, Object[] item, int[] accelerator, ActionListener listener)
public static JMenu createMenu(String name, Object[] item, int[] accelerator, ActionListener listener)
//package com.java2s; /*/* ww w. j ava 2 s. c o m*/ * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * Dualkarnevalen wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy us a beer in return * ---------------------------------------------------------------------------- */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Main { public static JMenu createMenu(String name, String prefix, Object[] item, int[] accelerator, ActionListener listener) { JMenu theMenu; int itemCounter; JMenuItem theItem; theMenu = new JMenu(name); if (item != null) for (itemCounter = 0; itemCounter < item.length; itemCounter++) { if (item[itemCounter] == null) theMenu.addSeparator(); else { if (item[itemCounter] instanceof JMenuItem) theItem = (JMenuItem) item[itemCounter]; else if (item[itemCounter] instanceof String) { theItem = new JMenuItem((String) item[itemCounter]); theItem.setActionCommand(prefix + item[itemCounter]); } else continue; if (listener != null) theItem.addActionListener(listener); if (accelerator.length > itemCounter && accelerator[itemCounter] != 0) theItem.setAccelerator(KeyStroke.getKeyStroke(accelerator[itemCounter], Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); theMenu.add(theItem); } } return theMenu; } public static JMenu createMenu(String name, Object[] item, int[] accelerator, ActionListener listener) { return createMenu(name, "", item, accelerator, listener); } }