New Line in Textfield
I Am Trying to Have Some Pre-Defined Text in My Textfield, but I Don't Know How to Add New Lines in Between the Words. I Tried \N, but It Isn't Working. Code...
I am trying to have some pre-defined text in my TextField, but I don't know how to add new lines in between the words. I tried \n, but it isn't working.
Code:
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);
}
}
Does anyone know how to add a newline between each word? I want there to be a separation between words and then it will automatically fill in the information later.
2 Answers
TextField is only for single lines, it will not render multiple lines as you want your code to achieve. so instead of using TextField use TextArea.
try to use the textarea instead of textfield. You can use the mulitple lines in textarea but textfield is a single line control