如何在JavaFX中创建文本区域?
文本区域是一个多行编辑器,您可以在其中输入文本。与以前的版本不同,在JavaFX的最新版本中,TextArea不允许在其中一行。您可以通过实例化javafx.scene.control.TextArea类来创建文本区域。
示例
下面的示例演示了TextArea的创建。
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class TextAreaExample extends Application {
public void start(Stage stage) {
//设置标签
Label label = new Label("Address");
Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 12);
label.setFont(font);
//创建分页
TextArea area = new TextArea();
//设置页数
area.setText("Enter your address here");
area.setPrefColumnCount(15);
area.setPrefHeight(120);
area.setPrefWidth(300);
//创建一个hbox来保存分页
HBox hbox = new HBox();
hbox.setSpacing(20);
hbox.setPadding(new Insets(20, 50, 50, 60));
hbox.getChildren().addAll(label, area);
//设置舞台
Group root = new Group(hbox);
Scene scene = new Scene(root, 595, 200, Color.BEIGE);
stage.setTitle("Text Area");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短