Here you can find the source of addRadioButton(JPanel buttonPanel, ButtonGroup group, String buttonName, boolean selected, ActionListener listener)
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 |
public static JRadioButton addRadioButton(JPanel buttonPanel, ButtonGroup group, String buttonName, boolean selected, ActionListener listener)
//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; } }