Java Reference
In-Depth Information
// When the selected radio button changes, set the appropriate style sheet
toggleGrp.selectedToggleProperty().addListener((ov, oldValue, newValue) -> {
String radioButtonText = ((RadioButton) toggleGrp.getSelectedToggle())
.getText();
sceneRef.getStylesheets().clear();
sceneRef.getStylesheets().addAll(radioButtonText);
});
stage.setTitle("On the Scene");
stage.show();
// Define an unmanaged node that will display Text
Text addedTextRef = new Text(0, -30, "");
addedTextRef.setTextOrigin(VPos.TOP);
addedTextRef.setFill(Color.BLUE);
addedTextRef.setFont(Font.font("Sans Serif", FontWeight.BOLD, 16));
addedTextRef.setManaged(false);
// Bind the text of the added Text node to the fill property of the Scene
addedTextRef.textProperty().bind(new SimpleStringProperty("Scene fill: ").
concat(sceneRef.fillProperty()));
// Add to the Text node to the FlowPane
((FlowPane) sceneRef.getRoot()).getChildren().add(addedTextRef);
}
}
Setting the Cursor for the Scene
The cursor can be set for a given node, for the entire scene, or for both. To do the latter, set the cursor property of the
Scene instance to one of the constant values in the Cursor class, as shown in the following snippet from Listing 2-2.
sceneRef.cursorProperty().bind(choiceBoxRef.getSelectionModel()
.selectedItemProperty());
These cursor values can be seen by looking at the javafx.scene.Cursor class in the JavaFX API docs; we've
created a collection of these constants in Listing 2-2.
Painting the Scene's Background
The Scene class has a fill property of type javafx.scene.paint.Paint . Looking at the JavaFX API will reveal that the
known subclasses of Paint are Color , ImagePattern , LinearGradient , and RadialGradient . Therefore, a Scene 's
background can be filled with solid colors, patterns, and gradients. If you don't set the fill property of the Scene , the
default color (white) will be used.
One of the Color constants is Color.TRANSPARENT , so you may make the Scene 's background completely
transparent if desired. in fact, the reason that the Scene behind the rounded-cornered rectangle in the stageCoach
screenshot in figure 2-5 isn't white is that its fill property is set to Color.TRANSPARENT (see Listing 2-1 again).
Tip
 
 
Search WWH ::




Custom Search