The CheckboxGroup lets multiple checkboxes work together to provide a mutually exclusion choice (at most one Checkbox can be selected at a time). Because the CheckboxGroup is neither a Component nor a Container, you should normally put all the Checkbox components associated with a CheckboxGroup in their own Panel (or other Container). The LayoutManager of the Panel should be GridLayout (0, 1) if you want them in one column. Figure 9.5 shows both a good way and bad way of positioning a set of Checkbox items in a CheckboxGroup. The image on the left is preferred because the user can sense that the items are grouped; the image on the right suggests three levels of different checkboxes and can therefore surprise the user when checkboxes are deselected.
This constructor creates an instance of CheckboxGroup.
The getSelectedCheckbox() method returns the Checkbox within the CheckboxGroup whose value is true. If no item is selected, null is returned.
getCurrent() is the Java 1.0 name for this method.
The setSelectedCheckbox() method makes checkbox the currently selected Checkbox within the CheckboxGroup. If checkboxis null, the method deselects all the items in the CheckboxGroup. If checkbox is not within the CheckboxGroup, nothing happens.
setCurrent() is the Java 1.0 name for this method.
The toString() method of CheckboxGroup creates a String representation of the current choice (as returned by getSelectedCheckbox()). Using the "straightforward" layout in Figure 9.5 as an example, the results would be:
java.awt.CheckboxGroup[current=java.awt.Checkbox[0,31,85x21, label=Helvetica,state=true]]
If there is no currently selected item, the results within the square brackets would be current=null.
This HTML Help has been published using the chm2web software. |