Java tutorial
//package com.java2s; import javax.swing.*; public class Main { public static JMenu menu(String name, JMenuItem... items) { final JMenu menu = new JMenu(name); for (JMenuItem item : items) { if (item != null) { menu.add(item); } else { menu.addSeparator(); } } return menu; } }