Tuesday, June 21, 2016

62. TextFlow

A TextFlow layout can be used to align text and other nodes.


We also apply a DropShadow effect.


package ex62;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.effect.DropShadow;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;

public class Ex62 extends Application {

    @Override
    public void start(Stage stage) {

        DropShadow dropShadow = new DropShadow();
        dropShadow.setOffsetX(4);
        dropShadow.setOffsetY(6);
        dropShadow.setColor(Color.PURPLE);
        
        Text text = new Text("A TextFlow Layout ");
        text.setFont(Font.font("Georgia", 64));
        text.setFill(Color.BLUE);
        text.setEffect(dropShadow);
        
        TextFlow root = new TextFlow(text);
        root.setTextAlignment(TextAlignment.CENTER);
        root.setLineSpacing(10);
        
        Scene scene = new Scene(root, 300, 300, Color.LIGHTGREEN);
        stage.setTitle("Example 62. TextFlow");
        stage.setScene(scene);
        stage.show();
    }
    
    public static void main(String[] args) {
        launch();
    }
}

This is the output:


No comments:

Post a Comment