Example usage for javax.swing ButtonGroup ButtonGroup

List of usage examples for javax.swing ButtonGroup ButtonGroup

Introduction

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

Prototype

public ButtonGroup() 

Source Link

Document

Creates a new ButtonGroup.

Usage

From source file:ToolbarDemo.java

protected JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    JMenu mFile = new JMenu("File");
    mFile.setMnemonic('f');

    ImageIcon iconNew = new ImageIcon("file_new.gif");
    Action actionNew = new AbstractAction("New", iconNew) {
        public void actionPerformed(ActionEvent e) {
            System.out.println("new action");
        }//from w  ww .ja  v a  2s .co  m
    };
    JMenuItem item = mFile.add(actionNew);
    mFile.add(item);

    ImageIcon iconOpen = new ImageIcon("file_open.gif");
    Action actionOpen = new AbstractAction("Open...", iconOpen) {
        public void actionPerformed(ActionEvent e) {
            System.out.println("open action");
        }
    };
    item = mFile.add(actionOpen);
    mFile.add(item);

    ImageIcon iconSave = new ImageIcon("file_save.gif");
    Action actionSave = new AbstractAction("Save...", iconSave) {
        public void actionPerformed(ActionEvent e) {
            System.out.println("save action");
        }
    };
    item = mFile.add(actionSave);
    mFile.add(item);

    mFile.addSeparator();

    Action actionExit = new AbstractAction("Exit") {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    item = mFile.add(actionExit);
    item.setMnemonic('x');
    menuBar.add(mFile);

    toolBar = new JToolBar();
    JButton btn1 = toolBar.add(actionNew);
    btn1.setToolTipText("New text");
    JButton btn2 = toolBar.add(actionOpen);
    btn2.setToolTipText("Open text file");
    JButton btn3 = toolBar.add(actionSave);
    btn3.setToolTipText("Save text file");

    ActionListener fontListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateMonitor();
        }
    };

    JMenu mFont = new JMenu("Font");
    mFont.setMnemonic('o');

    ButtonGroup group = new ButtonGroup();
    fontMenus = new JMenuItem[FontNames.length];
    for (int k = 0; k < FontNames.length; k++) {
        int m = k + 1;
        fontMenus[k] = new JRadioButtonMenuItem(m + " " + FontNames[k]);
        boolean selected = (k == 0);
        fontMenus[k].setSelected(selected);
        fontMenus[k].setMnemonic('1' + k);
        fontMenus[k].setFont(fonts[k]);
        fontMenus[k].addActionListener(fontListener);
        group.add(fontMenus[k]);
        mFont.add(fontMenus[k]);
    }

    mFont.addSeparator();

    boldMenu.setMnemonic('b');
    Font fn = fonts[1].deriveFont(Font.BOLD);
    boldMenu.setFont(fn);
    boldMenu.setSelected(false);
    boldMenu.addActionListener(fontListener);
    mFont.add(boldMenu);

    italicMenu.setMnemonic('i');
    fn = fonts[1].deriveFont(Font.ITALIC);
    italicMenu.setFont(fn);
    italicMenu.setSelected(false);
    italicMenu.addActionListener(fontListener);
    mFont.add(italicMenu);

    menuBar.add(mFont);

    getContentPane().add(toolBar, BorderLayout.NORTH);

    return menuBar;
}

From source file:MenuLookDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;/*from  w ww.ja v a 2 s. co  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:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java

/**
 * Constucts a JMenu named 'name' with a a RadioButton for each
 * object in 'themeArray'./*from w ww.  ja v a2s.  c om*/
 *
 * @param name the visible name for the Menu.
 * @param themeArray the array of themes to put in the menu.
 */
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themeNames = ResourceBundle.getBundle(BASE_NAME, Locale.getDefault());
    themes = themeArray;

    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem defaultItem = null;

    for (int i = 0; i < themes.length; i++) {
        String themeName;

        try {
            themeName = themeNames.getString(themes[i].getName().replaceAll("\\s", ""));
        } catch (MissingResourceException mre) {
            themeName = themes[i].getName();

            Object[] noResourceArgs = { themes[i].getName(), getLocale() };
            MessageFormat form = new MessageFormat(themeNames.getString("message.error.noResource"));
            log.error(form.format(noResourceArgs));
        }

        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themeName);
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);

        // Theme name without spaces is the key for looking up localized item text.
        item.setName(themes[i].getName().replaceAll(" ", ""));

        if (i == 0) {
            item.setSelected(true);
            defaultItem = item;
        }
    }

    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);

    defaultItem.doClick();
}

From source file:RadioButtonDemo.java

public RadioButtonDemo() {
    super(new BorderLayout());

    //Create the radio buttons.
    JRadioButton birdButton = new JRadioButton(birdString);
    birdButton.setMnemonic(KeyEvent.VK_B);
    birdButton.setActionCommand(birdString);
    birdButton.setSelected(true);//from  w  ww  . jav  a  2 s  .  c o  m

    JRadioButton catButton = new JRadioButton(catString);
    catButton.setMnemonic(KeyEvent.VK_C);
    catButton.setActionCommand(catString);

    JRadioButton dogButton = new JRadioButton(dogString);
    dogButton.setMnemonic(KeyEvent.VK_D);
    dogButton.setActionCommand(dogString);

    JRadioButton rabbitButton = new JRadioButton(rabbitString);
    rabbitButton.setMnemonic(KeyEvent.VK_R);
    rabbitButton.setActionCommand(rabbitString);

    JRadioButton pigButton = new JRadioButton(pigString);
    pigButton.setMnemonic(KeyEvent.VK_P);
    pigButton.setActionCommand(pigString);

    //Group the radio buttons.
    ButtonGroup group = new ButtonGroup();
    group.add(birdButton);
    group.add(catButton);
    group.add(dogButton);
    group.add(rabbitButton);
    group.add(pigButton);

    //Register a listener for the radio buttons.
    birdButton.addActionListener(this);
    catButton.addActionListener(this);
    dogButton.addActionListener(this);
    rabbitButton.addActionListener(this);
    pigButton.addActionListener(this);

    //Set up the picture label.
    picture = new JLabel(createImageIcon("images/" + birdString + ".gif"));

    //The preferred size is hard-coded to be the width of the
    //widest image and the height of the tallest image.
    //A real program would compute this.
    picture.setPreferredSize(new Dimension(177, 122));

    //Put the radio buttons in a column in a panel.
    JPanel radioPanel = new JPanel(new GridLayout(0, 1));
    radioPanel.add(birdButton);
    radioPanel.add(catButton);
    radioPanel.add(dogButton);
    radioPanel.add(rabbitButton);
    radioPanel.add(pigButton);

    add(radioPanel, BorderLayout.LINE_START);
    add(picture, BorderLayout.CENTER);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:MenuDemo.java

protected JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    JMenu menuFile = new JMenu("File");
    menuFile.setMnemonic('f');

    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setIcon(new ImageIcon("file_new.gif"));
    menuItem.setMnemonic('n');
    ActionListener lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("New");
        }/*from www  .  ja v a  2  s.c  o  m*/
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuItem = new JMenuItem("Open...");
    menuItem.setIcon(new ImageIcon("file_open.gif"));
    menuItem.setMnemonic('o');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MenuDemo.this.repaint();
            if (fileChooser.showOpenDialog(MenuDemo.this) != JFileChooser.APPROVE_OPTION)
                return;
            System.out.println(fileChooser.getSelectedFile());
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuItem = new JMenuItem("Save...");
    menuItem.setIcon(new ImageIcon("file_save.gif"));
    menuItem.setMnemonic('s');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Save...");
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);

    menuFile.addSeparator();

    menuItem = new JMenuItem("Exit");
    menuItem.setMnemonic('x');
    lst = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    menuItem.addActionListener(lst);
    menuFile.add(menuItem);
    menuBar.add(menuFile);

    ActionListener fontListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateMonitor();
        }
    };

    JMenu mFont = new JMenu("Font");
    mFont.setMnemonic('o');

    ButtonGroup group = new ButtonGroup();
    menus = new JMenuItem[FontNames.length];
    for (int i = 0; i < FontNames.length; i++) {
        int m = i + 1;
        menus[i] = new JRadioButtonMenuItem(m + " " + FontNames[i]);
        boolean selected = (i == 0);
        menus[i].setSelected(selected);
        menus[i].setMnemonic('1' + i);
        menus[i].setFont(fontArray[i]);
        menus[i].addActionListener(fontListener);
        group.add(menus[i]);
        mFont.add(menus[i]);
    }

    mFont.addSeparator();

    boldMenuItem = new JCheckBoxMenuItem("Bold");
    boldMenuItem.setMnemonic('b');
    Font fn = fontArray[1].deriveFont(Font.BOLD);
    boldMenuItem.setFont(fn);
    boldMenuItem.setSelected(false);
    boldMenuItem.addActionListener(fontListener);
    mFont.add(boldMenuItem);

    italicMenuItem = new JCheckBoxMenuItem("Italic");
    italicMenuItem.setMnemonic('i');
    fn = fontArray[1].deriveFont(Font.ITALIC);
    italicMenuItem.setFont(fn);
    italicMenuItem.setSelected(false);
    italicMenuItem.addActionListener(fontListener);
    mFont.add(italicMenuItem);

    menuBar.add(mFont);

    return menuBar;
}

From source file:com.mirth.connect.client.ui.MessageImportDialog.java

private void initComponents() {
    getContentPane().setBackground(UIConstants.BACKGROUND_COLOR);

    importFromLabel = new JLabel("Import From:");

    ActionListener importDestinationChanged = new ActionListener() {
        @Override/* w  w w . jav a2  s.co m*/
        public void actionPerformed(ActionEvent e) {
            if (importServerRadio.isSelected()) {
                fileTextField.setText(null);
                browseButton.setEnabled(false);
            } else {
                fileTextField.setText(null);
                browseButton.setEnabled(true);
            }
        }
    };

    importServerRadio = new MirthRadioButton("Server");
    importServerRadio.setSelected(true);
    importServerRadio.setBackground(UIConstants.BACKGROUND_COLOR);
    importServerRadio.addActionListener(importDestinationChanged);
    importServerRadio.setToolTipText(
            "<html>Import messages from a file, folder or archive<br />on the Mirth Connect Server.</html>");

    importLocalRadio = new MirthRadioButton("My Computer");
    importLocalRadio.setBackground(UIConstants.BACKGROUND_COLOR);
    importLocalRadio.addActionListener(importDestinationChanged);
    importLocalRadio.setToolTipText(
            "<html>Import messages from a file, folder<br />or archive on this computer.</html>");

    importFromButtonGroup = new ButtonGroup();
    importFromButtonGroup.add(importServerRadio);
    importFromButtonGroup.add(importLocalRadio);

    browseButton = new MirthButton("Browse...");
    browseButton.setEnabled(false);
    browseButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            browseSelected();
        }
    });

    fileLabel = new JLabel("File/Folder/Archive:");

    fileTextField = new MirthTextField();
    fileTextField.setToolTipText(
            "<html>A file containing message(s) in XML format, or a folder/archive<br />containing files with message(s) in XML format.</html>");

    subfoldersCheckbox = new MirthCheckBox("Include Sub-folders");
    subfoldersCheckbox.setSelected(true);
    subfoldersCheckbox.setBackground(UIConstants.BACKGROUND_COLOR);
    subfoldersCheckbox.setToolTipText(
            "<html>If checked, sub-folders of the folder/archive shown above<br />will be searched for messages to import.</html>");

    noteLabel = new JLabel(
            "<html><i>Note: RECEIVED, QUEUED, or PENDING messages will be set to ERROR upon import.</i></html>");

    importButton = new MirthButton("Import");
    importButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            importMessages();
        }
    });

    cancelButton = new MirthButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    });
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.DefItemEditorPanel.java

/**
 * @param numInUseArg/*from w  w  w. j  a va2s  .  c om*/
 * @param isRow
 */
protected void createUI(final int numInUseArg, final boolean isRow) {
    propsPanel = new RowColDefPanel(item, numInUseArg, isRow);
    autoPropsPanel = createAutoPropertyPanel(numInUseArg, isRow);

    cardPanel = new JPanel(cardLayout);
    cardPanel.add("Auto", autoPropsPanel);
    cardPanel.add("List", propsPanel);

    ActionListener action = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            isUsingAuto = autoCB.isSelected();
            cardLayout.show(cardPanel, isUsingAuto ? "Auto" : "List");
        }
    };
    autoCB = new JRadioButton("Auto");
    autoCB.addActionListener(action);
    listCB = new JRadioButton("List");
    listCB.addActionListener(action);
    ButtonGroup group = new ButtonGroup();
    group.add(autoCB);
    group.add(listCB);

    autoCB.setSelected(true);

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,16px,p,f:p:g", "p")); //$NON-NLS-1$ //$NON-NLS-2$
    pb.add(listCB, cc.xy(2, 1));
    pb.add(autoCB, cc.xy(4, 1));

    add(pb.getPanel(), BorderLayout.NORTH);
    add(cardPanel, BorderLayout.CENTER);

    cardLayout.show(cardPanel, "List");
    listCB.setSelected(true);
    isUsingAuto = false;

}

From source file:TabbedPaneTest.java

public TabbedPaneFrame() {
    setTitle("TabbedPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    tabbedPane = new JTabbedPane();
    // we set the components to null and delay their loading until the tab is shown
    // for the first time

    ImageIcon icon = new ImageIcon("yellow-ball.gif");

    tabbedPane.addTab("Mercury", icon, null);
    tabbedPane.addTab("Venus", icon, null);
    tabbedPane.addTab("Earth", icon, null);
    tabbedPane.addTab("Mars", icon, null);
    tabbedPane.addTab("Jupiter", icon, null);
    tabbedPane.addTab("Saturn", icon, null);
    tabbedPane.addTab("Uranus", icon, null);
    tabbedPane.addTab("Neptune", icon, null);
    tabbedPane.addTab("Pluto", null, null);

    final int plutoIndex = tabbedPane.indexOfTab("Pluto");
    JPanel plutoPanel = new JPanel();
    plutoPanel.add(new JLabel("Pluto", icon, SwingConstants.LEADING));
    JToggleButton plutoCheckBox = new JCheckBox();
    plutoCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tabbedPane.remove(plutoIndex);
        }//from w  w w.  j a v  a2 s .c o m
    });
    plutoPanel.add(plutoCheckBox);
    tabbedPane.setTabComponentAt(plutoIndex, plutoPanel);

    add(tabbedPane, "Center");

    tabbedPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {

            // check if this tab still has a null component

            if (tabbedPane.getSelectedComponent() == null) {
                // set the component to the image icon

                int n = tabbedPane.getSelectedIndex();
                loadTab(n);
            }
        }
    });

    loadTab(0);

    JPanel buttonPanel = new JPanel();
    ButtonGroup buttonGroup = new ButtonGroup();
    JRadioButton wrapButton = new JRadioButton("Wrap tabs");
    wrapButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            tabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
        }
    });
    buttonPanel.add(wrapButton);
    buttonGroup.add(wrapButton);
    wrapButton.setSelected(true);
    JRadioButton scrollButton = new JRadioButton("Scroll tabs");
    scrollButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        }
    });
    buttonPanel.add(scrollButton);
    buttonGroup.add(scrollButton);
    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:ScribbleDragAndDrop.java

/**
 * The main method. Creates a simple application using this class. Note the
 * buttons for switching between draw mode and drag mode.
 *///from w w  w . j  av  a 2  s. co m
public static void main(String[] args) {
    // Create a frame and put a scribble pane in it
    JFrame frame = new JFrame("ScribbleDragAndDrop");
    final ScribbleDragAndDrop scribblePane = new ScribbleDragAndDrop();
    frame.getContentPane().add(scribblePane, BorderLayout.CENTER);

    // Create two buttons for switching modes
    JToolBar toolbar = new JToolBar();
    ButtonGroup group = new ButtonGroup();
    JToggleButton draw = new JToggleButton("Draw");
    JToggleButton drag = new JToggleButton("Drag");
    draw.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scribblePane.setDragMode(false);
        }
    });
    drag.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scribblePane.setDragMode(true);
        }
    });
    group.add(draw);
    group.add(drag);
    toolbar.add(draw);
    toolbar.add(drag);
    frame.getContentPane().add(toolbar, BorderLayout.NORTH);

    // Start off in drawing mode
    draw.setSelected(true);
    scribblePane.setDragMode(false);

    // Pop up the window
    frame.setSize(400, 400);
    frame.setVisible(true);
}

From source file:components.MenuDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;/*from   ww  w.j  a v a2 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;
}