Java Reference
In-Depth Information
The code that follows sets the font and applies effects to Text nodes. It uses the
Serif, SanSerif, Dialog, and Monospaced fonts along with the drop shadow and reflec-
tion effects:
primaryStage.setTitle(“Chapter 14-3 Changing Text Fonts”);
Group root = new Group();
Scene scene = new Scene(root, 330, 250, Color.WHITE);
// Serif with drop shadow
Text java8Recipes2 = new Text(50, 50, “Java 8 Recipes”);
Font serif = Font.font(“Serif”, 30);
java8Recipes2.setFont(serif);
java8Recipes2.setFill(Color.RED);
DropShadow dropShadow = new DropShadow();
dropShadow.setOffsetX(2.0f);
dropShadow.setOffsetY(2.0f);
dropShadow.setColor(Color.rgb(50, 50, 50, .588));
java8Recipes2.setEffect(dropShadow);
root.getChildren().add(java8Recipes2);
// SanSerif
Text java8Recipes3 = new Text(50, 100, “Java 8 Recipes”);
Font sanSerif = Font.font(“SanSerif”, 30);
java8Recipes3.setFont(sanSerif);
java8Recipes3.setFill(Color.BLUE);
root.getChildren().add(java8Recipes3);
// Dialog
Text java8Recipes4 = new Text(50, 150, “Java 8 Recipes”);
Font dialogFont = Font.font(“Dialog”, 30);
java8Recipes4.setFont(dialogFont);
java8Recipes4.setFill(Color.rgb(0, 255, 0));
root.getChildren().add(java8Recipes4);
// Monospaced
Text java8Recipes5 = new Text(50, 200, “Java 8 Recipes”);
Font monoFont = Font.font(“Monospaced”, 30);
java8Recipes5.setFont(monoFont);
Search WWH ::




Custom Search