Java Reference
In-Depth Information
What causes
selectedIndexProperty
of the
genreSelectionModel
to change? To see the answer to this, we
have to revisit some code in Listing 1-3. In the following code snippet, the
setItems
method of
ChoiceBox
is used to
populate the
ChoiceBox
with items that each contain a genre.
genreChoiceBox = new ChoiceBox();
genreChoiceBox.setLayoutX(204);
genreChoiceBox.setLayoutY(154);
genreChoiceBox.setPrefWidth(93);
genreChoiceBox.setItems(acModel.genres);
This snippet from the model code in Listing 1-4 contains the collection to which the
ComboBox
items are bound:
/**
* List of some musical genres
*/
public ObservableList genres = FXCollections.observableArrayList(
"Chamber",
"Country",
"Cowbell",
"Metal",
"Polka",
"Rock"
);
When the user chooses a different item in the
ChoiceBox
, the
invalidationListener
is invoked. Looking again
at the code in the
invalidationListener
, you'll see that the value of the
selectedDBs
property changes, which as you
may recall, is bidirectionally bound to the slider. This is why the slider moves when you select a genre in the combo
box. Go ahead and test this by running the Audio Config program.
■
associating the
items
property of the
ChoiceBox
with an
ObservableList
causes the items in the
ChoiceBox
to be automatically updated when the elements in the underlying collection are modified.
Note
Surveying JavaFX Features
We close this chapter by surveying many of the features of JavaFX, some of which are a review for you. We do this by
describing several of the more commonly used packages and classes in the Java SDK API.
The
javafx.stage
package contains the following:
Stage
class, which is the top level of the UI containment hierarchy for any JavaFX
application, regardless of where it is deployed (e.g., the desktop, a browser, or a cell phone).
•
The
Screen
class, which represents the displays on the machine in which a JavaFX program is
running. This enables you to get information about the screens, such as size and resolution.
•
The
Search WWH ::
Custom Search