Thursday, June 23, 2016

69. TextArea

Unlike the TextField, we can enter many lines of text in TextArea.


Text is copied from the Wikipedia article on JavaFX and pasted into the TextArea. Because the text can not fit on one screen, vertical scrollbars appear.


package ex69;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class Ex69 extends Application {

    private TextArea textArea;

    @Override
    public void start(Stage stage) {

        Label label = new Label("TextArea");
        label.setFont(Font.font("Georgia", 20));
        
        textArea = new TextArea();
        textArea.setFont(Font.font("Georgia", 20));
        textArea.setWrapText(true);

        VBox root = new VBox(10, label, textArea);
        root.setAlignment(Pos.CENTER);
        root.setPadding(new Insets(20));
        
        Scene scene = new Scene(root, 400, 300);
        stage.setTitle("Example 69. TextArea");

        stage.setScene(scene);
        stage.show();
    }

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

This is the output:


No comments:

Post a Comment