Java examples for Swing:JRadioButton
JRadioButton is for single choice
import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; public class Main extends JFrame { JRadioButton[] teams = new JRadioButton[4]; public Main() { super("Choose an Output Format"); setSize(320, 120);//from w w w .ja v a2 s . c o m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); teams[0] = new JRadioButton("Atom"); teams[1] = new JRadioButton("RSS 0.92"); teams[2] = new JRadioButton("RSS 1.0"); teams[3] = new JRadioButton("RSS 2.0", true); JPanel panel = new JPanel(); JLabel chooseLabel = new JLabel( "Choose an output format for syndicated news items."); panel.add(chooseLabel); ButtonGroup group = new ButtonGroup(); for (JRadioButton team : teams) { group.add(team); panel.add(team); } add(panel); setVisible(true); } public static void main(String[] arguments) { Main ff = new Main(); } }