Java Reference
In-Depth Information
It returns
true
if the check box was just selected, and
false
if it was just cleared. Next, the
showAll( )
method is called, which displays all selected check boxes.
There is one other point of interest in the program. Notice that it uses a vertical flow
pane for the layout, as shown here:
By default,
FlowPane
flows horizontally. A vertical flow is created by passing the value
Orientation.VERTICAL
as the first argument to the
FlowPane
constructor.
Try This 17-1
Use the CheckBox Indeterminate State
As explained, by default,
CheckBox
implements two states: checked and unchecked.
However,
CheckBox
also supports a third, indeterminate state, which can be used to indic-
ate that the state of the box has not yet been set or that an option is not applicable to a situ-
ation. The indeterminate state for a check box must be explicitly enabled. It is not provided
by default. Also, the event handler for the check box must also handle the indeterminate
state. The project illustrates the process. It does so by adding support for the indeterminate
state to the
Smartphone
check box in
CheckboxDemo
program, just shown.
1.
To enable the indeterminate state in a check box, call
setAllowIndeterminate( )
,
shown here:
final void setAllowIndeterminate(boolean
enable
)
If
enable
is
true
, the indeterminate state is enabled. Otherwise, it is disabled. When
the indeterminate state is enabled, the user can select between checked, unchecked,
and indeterminate. Therefore, to enable the indeterminate state on the
Smartphone
check box, add this line:
2.
To determine if a check box is in the indeterminate state, call
isIndeterminate( )
,
shown here:
final boolean isIndeterminate( )