Java JRadioButtonMenuItem createJRadioButtonMenuItem(String name, String command, ActionListener listener, ButtonGroup buttonGroup, boolean isSelected)

Here you can find the source of createJRadioButtonMenuItem(String name, String command, ActionListener listener, ButtonGroup buttonGroup, boolean isSelected)

Description

Creates a radio button menu item with specified name, acton command and state.

License

Open Source License

Declaration

public static JRadioButtonMenuItem createJRadioButtonMenuItem(String name, String command,
        ActionListener listener, ButtonGroup buttonGroup, boolean isSelected) 

Method Source Code


//package com.java2s;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;

import javax.swing.JRadioButtonMenuItem;

public class Main {
    /**/*from ww w  .  j a  v  a  2  s. c o  m*/
     * Creates a radio button menu item with specified name, acton command and state.
     */
    public static JRadioButtonMenuItem createJRadioButtonMenuItem(String name, String command,
            ActionListener listener, ButtonGroup buttonGroup, boolean isSelected) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(name);
        item.setActionCommand(command);
        item.addActionListener(listener);
        item.setSelected(isSelected);
        if (buttonGroup != null) {
            buttonGroup.add(item);
        }
        return item;
    }

    /**
     * Creates a radio button menu item with specified name, acton command, state and enabled/disabled.
     */
    public static JRadioButtonMenuItem createJRadioButtonMenuItem(String name, String command,
            ActionListener listener, ButtonGroup buttonGroup, boolean isSelected, boolean isEnabled) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(name);
        item.setActionCommand(command);
        item.addActionListener(listener);
        item.setSelected(isSelected);
        item.setEnabled(isEnabled);
        if (buttonGroup != null) {
            buttonGroup.add(item);
        }
        return item;
    }

    /**
     * Creates a radio button menu item with specified name, acton command and button group.
     */
    public static JRadioButtonMenuItem createJRadioButtonMenuItem(String name, String command,
            ActionListener listener, ButtonGroup buttonGroup) {
        return createJRadioButtonMenuItem(name, command, listener, buttonGroup, false);
    }
}