- In various places within the different menus, menu separators divide the options into logical sets.
- Each of the menu options has a mnemonic associated with it to help with keyboard navigation and selection.
- The mnemonic allows users to make menu selections via the keyboard, for instance, by pressing Alt-F on a Windows platform to open the File menu.
- A keystroke associated with several options acts as a keyboard accelerator. Unlike the mnemonic, the accelerator can directly activate a menu option, even when the menu option isn't visible.
- The Options submenu has an icon associated with it.
JMenu fileMenu = new JMenu("File");
JMenuItem newMenuItem = new JMenuItem("New");
fileMenu.add(newMenuItem);
JMenuItem openMenuItem = new JMenuItem("Open");
fileMenu.add(openMenuItem);
JMenuItem closeMenuItem = new JMenuItem("Close");
fileMenu.add(closeMenuItem);
fileMenu.addSeparator();
JMenuItem saveMenuItem = new JMenuItem("Save");
fileMenu.add(saveMenuItem);
fileMenu.addSeparator();
JMenuItem exitMenuItem = new JMenuItem("Exit");
fileMenu.add(exitMenuItem);
Insert them at specific positions or insert a separator at a specific position
public JMenuItem insert(JMenuItem menuItem, int pos);
public JMenuItem insert(Action a, int pos);
public void insertSeparator(int pos);