Thursday, May 26, 2016

11. Text

A 3-line text is placed on the window using the Text class, with the font family "Georgia" at font size of 50.


We use the newline to split the string into 3 lines.


package ex11;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Ex11 extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        
        Text text = new Text(10,60,"Hello\nText\nWorld!");
        text.setFont(new Font("Georgia",50));
        
        Group root = new Group();
        root.getChildren().addAll(text);
        
        Scene scene = new Scene(root, 400, 200, Color.HONEYDEW);
        
        primaryStage.setTitle("Example 11. Text");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
    
}

This is the output:


No comments:

Post a Comment