TextField 文本输入框

文本输入组件(javafx.scene.control.TextField ),允许用户输入单行无格式化文本。与之前版本的JavaFX不同,TextField控件不支持多行输入,多行输入请使用 TextArea 控件。此外,如果您想要一种形式的富文本编辑,还可以使用HTMLEditor控件。

创建

TextField textField = new TextField();

添加到场景图

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;


public class TextFieldDemo extends Application  {


    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("HBox Experiment 1");

        TextField textField = new TextField();

        HBox hbox = new HBox(textField);

        Scene scene = new Scene(hbox, 200, 100);
        primaryStage.setScene(scene);
        primaryStage.show();

    }

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

显示效果

image.png