【发布时间】:2019-11-08 22:52:16
【问题描述】:
我正在处理一个文本框,该文本框将在其中提供有关主题的信息,但我希望 1 个长字符串将所有信息存储在其中。我希望将此字符串返回到该框中的“下一行”,我实际上是在尝试在 JavaFX 中创建一个文本框
【问题讨论】:
-
你在尝试时遇到了什么问题?
标签: java javafx text restriction
我正在处理一个文本框,该文本框将在其中提供有关主题的信息,但我希望 1 个长字符串将所有信息存储在其中。我希望将此字符串返回到该框中的“下一行”,我实际上是在尝试在 JavaFX 中创建一个文本框
【问题讨论】:
标签: java javafx text restriction
于是我又进行了一些挖掘,结果发现,我正在寻找的东西被称为“文本区域”
package com.jenkov.javafx.controls;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TextAreaExperiments extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("TextArea Experiment 1");
TextArea textArea = new TextArea();
VBox vbox = new VBox(textArea);
Scene scene = new Scene(vbox, 200, 100);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
【讨论】:
如果您基本上是想创建TextField,请尝试以下操作:
Label label1 = new Label("Name:");
TextField textField = new TextField ();
HBox hb = new HBox();
hb.getChildren().addAll(label1, textField);
hb.setSpacing(10);
【讨论】: