Java Reference
In-Depth Information
Figure 14-4 . TextFlow and FXML
How It Works
Solution 1 demonstrates how to apply fonts to text using standard Java code. Vector-
based graphics allow you to scale shapes and apply effects without issues of pixilation
(jaggies). JavaFX nodes use vector-based graphics. In each Text node, you can create
and set the font to be rendered onto the scene graph. Here is the code to create and set
the font on a Text node:
Text java8Recipes2 = new Text(50, 50, "Java 8 Recipes");
Font serif = Font.font("Serif", 30);
Java8Recipes2.setFont(serif);
In solution 1, the drop shadow is a real effect ( DropShadow ) object and is actu-
ally applied to a single Text node instance. The DropShadow object is set to be po-
sitioned based on an x and y offset in relation to the Text node. You also can set the
color of the shadow; here we set it to gray with a .588 opacity. Following is an example
of setting a Text node's effect property with a drop shadow effect ( DropShadow ):
DropShadow dropShadow = new DropShadow();
dropShadow.setOffsetX(2.0f);
dropShadow.setOffsetY(2.0f);
dropShadow.setColor(Color.rgb(50, 50, 50, .588));
java8Recipes2.setEffect(dropShadow);
Although this recipe is about setting text fonts, it also applied effects to Text
nodes. Another effect has been added (just kicking it up a notch). While creating the
last Text node using the monospaced font, the popular reflection effect is applied. The
code following code is set so that .8 or 80 percent of the reflection is shown. The re-
 
Search WWH ::




Custom Search