Check box is a two-mode selection component. The caption of the check box will be placed on the right side of the check box.
Clicking on the check box will change the state. The state is the
Boolean property of the Button,
and can be set with setValue() and obtained with
getValue() method of the
Property interface. Changing the value of a check box
will cause a ValueChangeEvent, which can be handled by
a ValueChangeListener.
/* A check box with default state (not checked, i.e., false). */
final CheckBox checkbox1 = new CheckBox("My CheckBox");
main.addComponent(checkbox1);
/* Another check box with explicitly set checked state. */
final CheckBox checkbox2 = new CheckBox("Checked CheckBox");
checkbox2.setValue(true);
main.addComponent(checkbox2);
/* Make some application logic. We use anynymous listener classes here.
* The above references were defined as "final" to allow accessing them
* from inside anonymous classes. */
checkbox1.addListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
/* Copy the value to the other checkbox. */
checkbox2.setValue(checkbox1.getValue());
}
});
checkbox2.addListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
/* Copy the value to the other checkbox. */
checkbox1.setValue(checkbox2.getValue());
}
});
For an example about the use of check box in a table, see Section 4.9, “Table”.
.i-checkbox { }