Creating a JRadioButton Component : Radio Button « Swing JFC « Java






Creating a JRadioButton Component

  

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;

public class Main {
  public static void main(String[] argv) throws Exception {
    Action action1 = new AbstractAction("RadioButton Label1") {
      public void actionPerformed(ActionEvent evt) {
      }
    };
    Action action2 = new AbstractAction("RadioButton Label2") {
      public void actionPerformed(ActionEvent evt) {
      }
    };

    JRadioButton b1 = new JRadioButton(action1);
    JRadioButton b2 = new JRadioButton(action2);

    ButtonGroup group = new ButtonGroup();
    group.add(b1);
    group.add(b2);

  }
}

   
    
  








Related examples in the same category

1.Radio Button Mnemonic KeyRadio Button Mnemonic Key
2.Using JRadioButtonsUsing JRadioButtons
3.A ButtonGroup voting boothA ButtonGroup voting booth
4.RadioButton DemoRadioButton Demo
5.React Radio button eventReact Radio button event
6.Working with the JRadioButtonWorking with the JRadioButton
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