Using a CheckBox

As you experienced in Step 17 of the exercise, the ScrollPane shown in Figure 6-9 contains a CheckBox. When the CheckBox is clicked, a message is printed to the Java console indicating the state of its selected property. The following code snippet, from Listing 6-12, implements this functionality in the StarterApp program:

final CheckBox checkBox = new CheckBox("CheckBox");
checkBox.setOnAction(e -> {
    System.out.print(e.getEventType() + " occurred on CheckBox");
    System.out.print(", and selectedProperty is: ");
    System.out.println(checkBox.selectedProperty().getValue());
});

A CheckBox may also represent a third indeterminate state by setting its allowIndeterminate property to true. This third state is typically represented in the CheckBox with a dash, and is useful for indicating that the state represented by the CheckBox is unknown.