TextField 中的新行
New Line in TextField
我想在我的 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);
}
}
有谁知道如何在每个单词之间添加一个换行符?
我希望单词之间有一个分隔符,然后它会在后面自动填充信息。
TextField
仅适用于单行,它不会呈现您希望代码实现的多行。所以不要使用 TextField
使用 TextArea
.
尝试使用文本区域而不是文本字段。您可以在 textarea 中使用多行,但 textfield 是单行控件
我想在我的 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);
}
}
有谁知道如何在每个单词之间添加一个换行符? 我希望单词之间有一个分隔符,然后它会在后面自动填充信息。
TextField
仅适用于单行,它不会呈现您希望代码实现的多行。所以不要使用 TextField
使用 TextArea
.
尝试使用文本区域而不是文本字段。您可以在 textarea 中使用多行,但 textfield 是单行控件