文本字段中的新行

Imp*_*ion 2 java javafx javafx-8

我试图在我的 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);

    }

}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何在每个单词之间添加换行符?我希望单词之间有一个分隔,然后它会在以后自动填写信息。

小智 5

TextField仅适用于单行,它不会像您希望代码实现的那样呈现多行。所以不要使用TextFielduse TextArea。