Java Reference
In-Depth Information
private void createControls(GridPane grid) {
final Label volumeLabel = new Label("Volume");
final Label rateLabel = new Label("Rate");
final Label balanceLabel = new Label("Balance");
GridPane.setHalignment(volumeLabel, HPos.CENTER);
GridPane.setHalignment(rateLabel, HPos.CENTER);
GridPane.setHalignment(balanceLabel, HPos.CENTER);
volumeSlider = new Slider(0.0, 1.0, 1.0);
rateSlider = new Slider(0.25, 2.5, 1.0);
balanceSlider = new Slider(-1.0, 1.0, 0.0);
GridPane.setHgrow(volumeSlider, Priority.ALWAYS);
GridPane.setHgrow(rateSlider, Priority.ALWAYS);
GridPane.setHgrow(balanceSlider, Priority.ALWAYS);
grid.add(volumeLabel, 0, 2);
grid.add(volumeSlider, 0, 3);
grid.add(rateLabel, 1, 2);
grid.add(rateSlider, 1, 3);
grid.add(balanceLabel, 2, 2);
grid.add(balanceSlider, 2, 3);
}
Listing 9-5 shows the
createClipList
method. This method creates a
VBox
to hold a
Label
, the three
Button
s that play the
AudioClip
s, and a
Hyperlink
that triggers the display of the Code Monkey web page at
jonathancoulton.com
in a separate window. The
VBox
is then added to the
GridPane
such that it spans all remaining
columns in the first row. The
VBox
is always centered horizontally in the grid and grows in both the horizontal and
vertical directions, taking up whatever extra space is available in the layout.
Listing 9-5.
Constructing the Buttons That Play the
AudioClip
s
private void createClipList(GridPane grid) {
final VBox vbox = new VBox(30);
vbox.setAlignment(Pos.TOP_CENTER);
final Label clipLabel = new Label("Code Monkey To-Do List:");
clipLabel.setId("clipLabel");
final Button getUpButton = new Button("Get Up, Get Coffee");
getUpButton.setPrefWidth(300);
getUpButton.setOnAction(createPlayHandler(coffeeClip));
final Button goToJobButton = new Button("Go to Job");
goToJobButton.setPrefWidth(300);
goToJobButton.setOnAction(createPlayHandler(jobClip));
final Button meetingButton = new Button("Have Boring Meeting");
meetingButton.setPrefWidth(300);
meetingButton.setOnAction(createPlayHandler(meetingClip));
Search WWH ::
Custom Search