Java Reference
In-Depth Information
predefined values. For example, to specify gender, the user would select either male or
female; similarly, a student would select either undergraduate or graduate. In addition to
freeing the user from typing in such values, to get precise input, you want the user to
select a value from a given set.
The JCheckBox and JRadioButton classes allow a user to select a value from a set of
given values. These classes are both subclasses of the abstract class ToggleButton .
The class JCheckBox is described in this
section;
the class JRadioButton is
discussed in the next section.
Table 12-10 shows some of the constructors and methods of the class JCheckBox .
TABLE 12-10 Some Constructors and Methods of the class JCheckBox
public JCheckBox()
//Creates an initially unselected check box button
//with no label and no icon.
//Example: JCheckBox myJCheckBox = new JCheckBox()
//
myJCheckBox points to the check box with no label
//
and no icon.
public JCheckBox(Icon icon)
//Creates an initially unselected check box button with
//the specified icon and no label.
//Example: JCheckBox myJCheckBox = new JCheckBox(anIcon);
//
myJCheckBox points to the check box with the
//
icon "anIcon".
public JCheckBox(Icon icon, boolean selected)
//Creates a check box with the specified
//image and selection state, but with no label.
//Example: JCheckBox myJCheckBox =
//
new JCheckBox(anIcon, true);
//
myJCheckBox points to the selected check box with
//
anIcon as the icon.
public JCheckBox(String text)
//Creates an unselected check box with
//the specified label.
//Example: JCheckBox myJCheckBox = new JCheckBox("Box");
//
1
2
myJCheckBox points to the unselected check box with
//
the label "Box".
public JCheckBox(String text, boolean selected)
//Creates a check box with the specified
//label and selection state.
//Example: JCheckBox myJCheckBox =
//
new JCheckBox("Box", false);
//
myJCheckBox points to the unselected check box with
//
the label "Box".
 
Search WWH ::




Custom Search