【发布时间】:2018-04-02 18:51:06
【问题描述】:
我试图在我的 TextField 中添加一些预定义的文本,但我不知道如何在单词之间添加新行。我试过\n,但它不起作用。
代码:
package view;
import javafx.scene.text.Text;
public class Overview extends VBox{
private TextField info;
public Overview() {
//Adds a little border around the app so the text field doesn't go to the edges
this.setPadding(new Insets(30, 30, 30, 30));
//----- Initialising text field --------
info = new TextField("Name:\n" + "PNumber:\n"+ "Email:\n"+ "Date:\n"+ "Course:\n"+ ""+ "Selected Modules:\n"+ "==============");
info.setAlignment(Pos.TOP_LEFT);
info.setMinHeight(850);
info.setEditable(false);
//------ Adding the text to the Text Field --------
//-------- Putting it into VBox so that it stretches with the screen ----------
VBox fit = new VBox(info);
this.getChildren().add(fit);
}
}
有谁知道如何在每个单词之间添加换行符? 我希望单词之间有一个分隔,然后它会在以后自动填写信息。
【问题讨论】:
-
使用
TextArea而不是TextField -
@Rishaldevsingh 已经解决了,谢谢:D
-
很高兴,请接受答案:)