Java Swing Tutorial - Java ButtonGroup .setSelected (ButtonModel m, boolean b)








Syntax

ButtonGroup.setSelected(ButtonModel m, boolean b) has the following syntax.

public void setSelected(ButtonModel m,  boolean b)

Example

In the following code shows how to use ButtonGroup.setSelected(ButtonModel m, boolean b) method.

// w  w w .ja  v a 2  s .  c o  m
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JRadioButton;

public class Main {
  public static void main(String[] argv) throws Exception {

    JRadioButton radioButton = new JRadioButton();
    ButtonGroup group = new ButtonGroup();
    ButtonModel model = radioButton.getModel();
    group.setSelected(model, true);

  }
}