Java Reference
In-Depth Information
Once the random values are generated, they will be applied to the Text nodes,
which will be drawn onto the scene graph. The following code snippet applies position
(x, y), color (RGB), and rotation (angle in degrees) onto the Text node:
Text text = new Text(x, y, "Java 8 Recipes");
text.setFill(Color.rgb(red, green, blue, .99));
text.setRotate(rot);
root.getChildren().add(text);
You will begin to see the power of the scene graph API by its ease of use. Text
nodes can be easily manipulated as if they were Shapes . Well, actually they are
Shapes . Defined in the inheritance hierarchy, Text nodes extend from the
javafx.scene.shape.Shape class and are therefore capable of doing interesting
things such as being filled with colors or rotated about an angle. Although the text is
colorized, this still tends to be somewhat boring. However, in the next recipe you will
learn how to change a text's font.
14-3. Changing Text Fonts
Problem
You want to change text fonts and add special effects to the Text nodes.
Solution 1
Create a JavaFX application that uses the following classes to set the text font and ap-
ply embedded effects to Text nodes:
javafx.scene.text.Font
javafx.scene.effect.DropShadow
javafx.scene.effect.Reflection
Search WWH ::




Custom Search