Working with the JRadioButton : Radio Button « Swing JFC « Java






Working with the JRadioButton

Working with the JRadioButton
  
import java.awt.Container;
import java.awt.GridLayout;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

public class SwingRadioButtonTest {
  public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(0, 1));
    ButtonGroup group = new ButtonGroup();
    JRadioButton option = new JRadioButton("French Fries", true);
    group.add(option);
    contentPane.add(option);
    option = new JRadioButton("Onion Rings", false);
    group.add(option);
    contentPane.add(option);
    option = new JRadioButton("Ice Cream", false);
    group.add(option);
    contentPane.add(option);
    frame.setSize(200, 200);
    frame.show();
  }
}
           
         
    
  








Related examples in the same category

1.Creating a JRadioButton Component
2.Radio Button Mnemonic KeyRadio Button Mnemonic Key
3.Using JRadioButtonsUsing JRadioButtons
4.A ButtonGroup voting boothA ButtonGroup voting booth
5.RadioButton DemoRadioButton Demo
6.React Radio button eventReact Radio button event
7.ButtonGroup DemoButtonGroup Demo
8.Group RadioButtonGroup RadioButton
9.Group Action RadioButtonGroup Action RadioButton
10.Implement group of buttons in an application
11.Selecting a JRadioButton Component in a Button Group
12.A frame with a sample text label and radio buttons for selecting font sizesA frame with a sample text label and radio buttons for selecting font sizes