Java JButton Settings addRadioButton(JPanel buttonPanel, ButtonGroup group, String buttonName, boolean selected, ActionListener listener)

Here you can find the source of addRadioButton(JPanel buttonPanel, ButtonGroup group, String buttonName, boolean selected, ActionListener listener)

Description

------------------------------------------------------------- addRadioButton

License

Open Source License

Parameter

Parameter Description
buttonPanel JPanel
group ButtonGroup
buttonName String
selected boolean - is the button selected
listener ActionListener - class in which the actionPerformed methods is found. default is that buttons will be centered must set the alignment in the calling buttonPanel

Return

JRadioButton

Declaration

public static JRadioButton addRadioButton(JPanel buttonPanel,
        ButtonGroup group, String buttonName, boolean selected,
        ActionListener listener) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;

import java.awt.event.ActionListener;

public class Main {
    /**//www  .ja  v  a 2  s  . com
     * -------------------------------------------------------------
     * addRadioButton
     *
     * @param buttonPanel JPanel
     * @param group       ButtonGroup
     * @param buttonName  String
     * @param selected    boolean - is the button selected
     * @param listener    ActionListener - class in which the actionPerformed methods is found.
     *                    default is that buttons will be centered
     *                    must set the alignment in the calling buttonPanel
     * @return JRadioButton
     */
    public static JRadioButton addRadioButton(JPanel buttonPanel,
            ButtonGroup group, String buttonName, boolean selected,
            ActionListener listener) {
        JRadioButton button = new JRadioButton(buttonName, selected);
        button.addActionListener(listener);
        //set the name of the button in the model as well since the ButtonModel
        // is all we can get from the button group.
        (button.getModel()).setActionCommand(buttonName);

        group.add(button);
        buttonPanel.add(button);
        return button;
    }
}

Related

  1. addButton(Container component, String text, Icon icon, ActionListener listener, String actionCommand)
  2. addButton(String name, JPanel panel, ActionListener action)
  3. addButtonInPanel(Container component, String text, ActionListener listener)
  4. addButtonToPanel(JPanel panel, Object constraints, String text)
  5. addMiddleButtonDragSupport(Component targetComponent)
  6. addToButtonGroup(ButtonGroup bg, T button)
  7. applyDefaultProperties(final Button comp)
  8. askYesNoQuestion(String dlgTitle, String question, Component parent, Object[] buttonTittle)
  9. buttonGroup(AbstractButton b1, AbstractButton b2)