Java Reference
In-Depth Information
18.2.2 Check Boxes
A check box is a user-interface component with two states: checked and unchecked.
You use a group of check boxes when one selection does not exclude another. For
example, the choices for ȒBoldȓ and ȒItalicȓ in Figure 4 are not exclusive. You can
choose either, both, or neither. Therefore, they are implemented as a set of separate
check boxes. Radio buttons and check boxes have different visual appearances.
Radio buttons are round and have a black dot when selected. Check boxes are
square and have a check mark when selected. (Strictly speaking, the appearance
depends on the chosen look and feel. It is possible to create a different look and feel
in which check boxes have a different shape or in which they give off a particular
sound when selected.)
For a binary choice, use a check box.
You construct a check box by giving the name in the constructor:
JCheckBox italicCheckBox = new JCheckBox("Italic");
Do not place check boxes inside a button group.
18.2.3 Combo Boxes
If you have a large number of choices, you don't want to make a set of radio
buttons, because that would take up a lot of space. Instead, you can use a combo
box. This component is called a combo box because it is a combination of a list and
a text field. The text field displays the name of the current selection. When you
click on the arrow to the right of the text field of a combo box, a list of selections
drops down, and you can choose one of the items in the list (see Figure 5 ).
For a large set of choices, use a combo box.
If the combo box is editable, you can also type in your own selection. To make a
combo box editable, call the setEditable method.
You add strings to a combo box with the addItem method.
Search WWH ::




Custom Search