Checkbox groups are collections of checkboxes with the special property that no more than one checkbox in the same group can be selected at a time. The checkboxes in a CheckboxGroup are often called radio buttons. Checkboxes that are members of the same CheckboxGroup cannot be checked simultaneously. When the user checks one, all others are unchecked automatically.

The constructor for a CheckboxGroup is trivial. No arguments are needed. You do not even need to add the CheckboxGroup to the applet since checkbox groups are themselves not user-interface widgets, just ways of arranging checkboxes.

CheckboxGroup cbg = new CheckboxGroup();

To make check boxes act like radio buttons, use this constructor for each Checkbox in the group.

public Checkbox(String label, CheckboxGroup cbg, boolean checked)

The label is the label for this Checkbox. The CheckboxGroup is the group you want this Checkbox to belong to and must already exist.

At any time, you can get or set the selected Checkbox with these two methods:

  public Checkbox getSelectedCheckbox()
  public void setSelectedCheckbox(Checkbox box)

Previous | Next | Top | Cafe au Lait

Copyright 1997-1999 Elliotte Rusty Harold
Last Modified June 30, 1999