Example usage for javax.swing JMenu setMnemonic

List of usage examples for javax.swing JMenu setMnemonic

Introduction

In this page you can find the example usage for javax.swing JMenu setMnemonic.

Prototype

@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic")
public void setMnemonic(int mnemonic) 

Source Link

Document

Sets the keyboard mnemonic on the current model.

Usage

From source file:misc.TextBatchPrintingDemo.java

/**
 * Create and display the main application frame.
 *///from  www.  ja  v a2  s  .c  o m
void createAndShowGUI() {
    messageArea = new JLabel(defaultMessage);

    selectedPages = new JList(new DefaultListModel());
    selectedPages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectedPages.addListSelectionListener(this);

    setPage(homePage);

    JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(pageItem),
            new JScrollPane(selectedPages));

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);

    /** Menu item and keyboard shortcuts for the "add page" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Add Page") {
        public void actionPerformed(ActionEvent e) {
            DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
            pages.addElement(pageItem);
            selectedPages.setSelectedIndex(pages.getSize() - 1);
        }
    }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "print selected" command.*/
    fileMenu.add(createMenuItem(new AbstractAction("Print Selected") {
        public void actionPerformed(ActionEvent e) {
            printSelectedPages();
        }
    }, KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "clear selected" command.*/
    fileMenu.add(createMenuItem(new AbstractAction("Clear Selected") {
        public void actionPerformed(ActionEvent e) {
            DefaultListModel pages = (DefaultListModel) selectedPages.getModel();
            pages.removeAllElements();
        }
    }, KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)));

    fileMenu.addSeparator();

    /** Menu item and keyboard shortcuts for the "home page" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Home Page") {
        public void actionPerformed(ActionEvent e) {
            setPage(homePage);
        }
    }, KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK)));

    /** Menu item and keyboard shortcuts for the "quit" command.  */
    fileMenu.add(createMenuItem(new AbstractAction("Quit") {
        public void actionPerformed(ActionEvent e) {
            for (Window w : Window.getWindows()) {
                w.dispose();
            }
        }
    }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)));

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    contentPane.add(pane);
    contentPane.add(messageArea);

    JFrame frame = new JFrame("Text Batch Printing Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menuBar);
    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    if (printService == null) {
        // Actual printing is not possible, issue a warning message.
        JOptionPane.showMessageDialog(frame, "No default print service", "Print Service Alert",
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:components.MenuLookDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//from  www.j  a  va  2  s.c  o m
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:MenuLookDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//from  w ww . j  a v  a  2  s  .  c o m
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    // Create the menu bar.
    menuBar = new JMenuBar();

    // Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    // a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    // menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menu.add(menuItem);

    // a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    menu.add(rbMenuItem);

    // a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    menu.add(cbMenuItem);

    // a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    submenu.add(menuItem);
    menu.add(submenu);

    // Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:daylightchart.gui.DaylightChartGui.java

private void createHelpMenu(final JMenuBar menuBar, final JToolBar toolBar) {

    final GuiAction onlineHelp = new OnlineHelpAction();
    final GuiAction about = new AboutAction(DaylightChartGui.this);

    final JMenu menuHelp = new JMenu(Messages.getString("DaylightChartGui.Menu.Help")); //$NON-NLS-1$
    menuHelp.setMnemonic('H');

    menuHelp.add(onlineHelp);/*from w w w .  j  a  v a 2 s .c  o m*/
    menuHelp.add(about);
    menuBar.add(menuHelp);

    toolBar.addSeparator();
    toolBar.add(onlineHelp);

}

From source file:daylightchart.gui.DaylightChartGui.java

private void createActions(final JMenuBar menuBar, final JToolBar toolBar) {
    final JMenu menu = new JMenu(Messages.getString("DaylightChartGui.Menu.Actions")); //$NON-NLS-1$
    menu.setMnemonic('A');

    for (final LocationsListOperation operation : LocationsListOperation.values()) {
        final GuiAction action = operation.getAction(this);
        menu.add(action);/* ww w.  jav  a  2 s. c  o m*/
    }

    menu.addSeparator();
    menu.add(new GetCountriesFilesAction());
    menu.add(new GetUSStatesFilesAction());

    menu.addSeparator();
    menu.add(new CloseCurrentTabAction(locationsTabbedPane));

    menuBar.add(menu);
}

From source file:be.fedict.eid.tsl.tool.TslTool.java

private void initNewMenu(JMenu fileMenu) {
    JMenu newMenu = new JMenu("New");
    newMenu.setMnemonic(KeyEvent.VK_N);
    fileMenu.add(newMenu);/*from www. java 2 s.  c om*/

    JMenu belgiumMenu = new JMenu("Belgium");
    newMenu.add(belgiumMenu);

    JMenu _2010BelgiumMenu = new JMenu("2010");
    belgiumMenu.add(_2010BelgiumMenu);

    JMenuItem _2010_T1_BelgiumMenuItem = addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2010-T1",
            _2010BelgiumMenu, true);
    _2010BelgiumMenu.add(_2010_T1_BelgiumMenuItem);

    JMenuItem _2010_T2_BelgiumMenuItem = addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2010-T2",
            _2010BelgiumMenu, true);
    _2010BelgiumMenu.add(_2010_T2_BelgiumMenuItem);

    JMenuItem _2010_T3_BelgiumMenuItem = addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2010-T3",
            _2010BelgiumMenu, true);
    _2010BelgiumMenu.add(_2010_T3_BelgiumMenuItem);

    JMenu _2011BelgiumMenu = new JMenu("2011");
    belgiumMenu.add(_2011BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2011-T1", _2011BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2011-T2", _2011BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2011-T3", _2011BelgiumMenu, true);

    JMenu _2012BelgiumMenu = new JMenu("2012");
    belgiumMenu.add(_2012BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2012-T1", _2012BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2012-T2", _2012BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2012-T3", _2012BelgiumMenu, true);

    JMenu _2013BelgiumMenu = new JMenu("2013");
    belgiumMenu.add(_2013BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2013-T1", _2013BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2013-T2", _2013BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2013-T3", _2013BelgiumMenu, true);

    JMenu _2014BelgiumMenu = new JMenu("2014");
    belgiumMenu.add(_2014BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2014-T1", _2014BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_1, "TSL-BE-2014-T2", _2014BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_1, "TSL-BE-2014-T3", _2014BelgiumMenu, true);

    JMenu _2015BelgiumMenu = new JMenu("2015");
    belgiumMenu.add(_2015BelgiumMenu);

    addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2015-T1", _2015BelgiumMenu, true);
    addActionMenuItem("Trimester 2", KeyEvent.VK_1, "TSL-BE-2015-T2", _2015BelgiumMenu, true);
    addActionMenuItem("Trimester 3", KeyEvent.VK_1, "TSL-BE-2015-T3", _2015BelgiumMenu, true);

}

From source file:com.qspin.qtaste.ui.MainPanel.java

protected void genMenu(final TestCaseTree tct) {
    final JFrame owner = this;
    JMenuBar menuBar = new JMenuBar();
    JMenu tools = new JMenu("Tools");
    tools.setMnemonic(KeyEvent.VK_T);

    // Tools|Config menu item
    JMenuItem config = new JMenuItem("Config", KeyEvent.VK_D);
    config.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            //ATEConfigEditPanel configPanel = new  ATEConfigEditPanel(null);
            //configPanel.setVisible(true);
            MainConfigFrame configFrame = new MainConfigFrame();
            configFrame.launch();// w ww  .  j  av a  2  s.  c o m
            configFrame.addWindowListener(new WindowListener() {

                public void windowOpened(WindowEvent e) {
                }

                public void windowClosing(WindowEvent e) {
                }

                public void windowClosed(WindowEvent e) {
                    // refresh the Configuration information display
                    refreshParams();
                }

                public void windowIconified(WindowEvent e) {
                }

                public void windowDeiconified(WindowEvent e) {
                }

                public void windowActivated(WindowEvent e) {
                }

                public void windowDeactivated(WindowEvent e) {
                }
            });

        }
    });
    tools.add(config);

    // Tools|delete results menu item
    JMenuItem deleteResults = new JMenuItem("Delete Results", KeyEvent.VK_D);
    final MainPanel ui = this;
    deleteResults.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String baseDir = TestEngineConfiguration.getInstance().getString("reporting.generated_report_path");
            new File(baseDir, baseDir);
            // TO DO : delete really the files
            JOptionPane.showMessageDialog(ui, "Results have been deleted");

        }
    });
    tools.add(deleteResults);

    JMenu fileMenu = new JMenu("File");
    JMenuItem importTestSuites = new JMenuItem("Import TestSuites");
    importTestSuites.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            //
            mTestCasePanel.importTestSuites();

        }
    });
    fileMenu.add(importTestSuites);

    JMenu help = new JMenu("Help");
    help.setMnemonic(KeyEvent.VK_H);
    JMenuItem about = new JMenuItem("About", KeyEvent.VK_A);
    about.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new AboutDialog(owner);
        }
    });
    help.add(about);

    JMenuItem ateUserManuel = new JMenuItem("User Manual");
    ateUserManuel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            viewQTasteUserManuel();
        }
    });
    help.add(ateUserManuel);

    //menuBar.add(tools); // not to be used at this time!!!!!!!!!
    //menuBar.add(fileMenu);
    menuBar.add(help);
    setJMenuBar(menuBar);
}

From source file:daylightchart.gui.DaylightChartGui.java

private void createFileMenu(final JMenuBar menuBar, final JToolBar toolBar) {

    final GuiAction openLocationsFile = new OpenLocationsFileAction(this);
    final GuiAction saveLocationsFile = new SaveLocationsFileAction(this);
    final GuiAction saveChart = new SaveChartAction(this);
    final GuiAction printChart = new PrintChartAction(locationsTabbedPane);

    final ExitAction exit = new ExitAction(this, Messages.getString("DaylightChartGui.Menu.File.Exit")); //$NON-NLS-1$

    final JMenu menu = new JMenu(Messages.getString("DaylightChartGui.Menu.File")); //$NON-NLS-1$
    menu.setMnemonic('F');

    recentLocationsMenu = new JMenu(Messages.getString("DaylightChartGui.Menu.File.RecentLocations")); //$NON-NLS-1$
    menu.setMnemonic('R');

    menu.add(openLocationsFile);//ww  w .ja v a  2  s  . c  o m
    menu.add(saveLocationsFile);
    menu.addSeparator();
    menu.add(saveChart);
    if (!isSlimUi()) {
        menu.add(printChart);
    }
    menu.addSeparator();
    menu.add(recentLocationsMenu);
    menu.addSeparator();
    menu.add(exit);
    menuBar.add(menu);

    toolBar.add(openLocationsFile);
    toolBar.add(saveLocationsFile);
    toolBar.addSeparator();
    toolBar.add(saveChart);
    toolBar.add(printChart);
    toolBar.addSeparator();

}

From source file:daylightchart.gui.DaylightChartGui.java

private void createOptionsMenu(final JMenuBar menuBar, final JToolBar toolBar) {

    final JMenu menu = new JMenu(Messages.getString("DaylightChartGui.Menu.Options")); //$NON-NLS-1$
    menu.setMnemonic('O');

    final GuiAction options = new OptionsAction(this);
    menu.add(options);/*from   w  ww.jav  a  2 s  .  c  o  m*/

    final GuiAction chartOptions = new ChartOptionsAction(this);
    menu.add(chartOptions);

    final GuiAction resetAll = new ResetAllAction(this);
    menu.add(resetAll);

    menu.addSeparator();

    final JCheckBoxMenuItem slimUiMenuItem = new JCheckBoxMenuItem(
            Messages.getString("DaylightChartGui.Menu.Options.SlimUi")); //$NON-NLS-1$
    slimUiMenuItem.setState(isSlimUi());
    slimUiMenuItem.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(final ItemEvent e) {
            final boolean slimUi = e.getStateChange() == ItemEvent.SELECTED;
            final Options options = UserPreferences.optionsFile().getData();
            options.setSlimUi(slimUi);
            UserPreferences.optionsFile().save(options);
            ResetAllAction.restart(DaylightChartGui.this, slimUi);
        }
    });
    menu.add(slimUiMenuItem);

    menuBar.add(menu);

    toolBar.add(options);
    toolBar.add(chartOptions);
    toolBar.addSeparator();
}

From source file:components.MenuDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;/*from  w w w. j a v a  2 s . c  om*/
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}