Java Reference
In-Depth Information
The getter methods for property
values are provided in the class, but
omitted in the UML diagram for brevity.
javafx.scene.text.Font
-size: double
-name: String
-family: String
The size of this font.
The name of this font.
The family of this font.
+Font(size: double)
+Font(name: String, size:
double)
+font(name: String, size:
double)
+font(name: String, w:
FontWeight, size: double)
+font(name: String, w: FontWeight,
p: FontPosture, size: double)
+getFamilies(): List<String>
+getFontNames(): List<String>
Creates a Font with the specified size.
Creates a Font with the specified full font name and size.
Creates a Font with the specified name and size.
Creates a Font with the specified name, weight, and size.
Creates a Font with the specified name, weight, posture, and size.
Returns a list of font family names.
Returns a list of full font names including family and weight.
F IGURE 14.10
Font encapsulates information about fonts.
L ISTING 14.8
FontDemo.java
1 import javafx.application.Application;
2 import javafx.scene.Scene;
3 import javafx.scene.layout.*;
4 import javafx.scene.paint.Color;
5 import javafx.scene.shape.Circle;
6 import javafx.scene.text.*;
7 import javafx.scene.control.*;
8 import javafx.stage.Stage;
9
10 public class FontDemo extends Application {
11 @Override // Override the start method in the Application class
12
public void start(Stage primaryStage) {
13
// Create a pane to hold the circle
14
Pane pane = new StackPane();
create a StackPane
15
16 // Create a circle and set its properties
17 Circle circle = new Circle();
18 circle.setRadius( 50 );
19 circle.setStroke(Color.BLACK);
20 circle.setFill( new Color( 0.5 , 0.5 , 0.5 , 0.1 ));
21
create a Circle
create a Color
add circle to the pane
pane.getChildren().add(circle); // Add circle to the pane
22
23 // Create a label and set its properties
24 Label label = new Label( " JavaFX " );
25 label.setFont(Font.font( " Times New Roman " ,
26
create a label
create a font
FontWeight.BOLD, FontPosture.ITALIC, 20 ));
27
pane.getChildren().add(label);
add label to the pane
28
29 // Create a scene and place it in the stage
30 Scene scene = new Scene(pane);
31 primaryStage.setTitle( " FontDemo " ); // Set the stage title
32 primaryStage.setScene(scene); // Place the scene in the stage
 
 
Search WWH ::




Custom Search