Reputation: 37
In my project, I and taking four strings from text fields and putting them together in a different text field using the setText in Java. I need them to be in four different lines, but right now there are all in a line with no spaces between them
How do I break the line between the different strings.
I tried using the \n
, but I just got an error.
Here is the line of code I am using
display.setText(manu+brand+year+price);
which gives me this output
fordfocus20003500.0
I want
ford
focus
2000
3500.0
Upvotes: 0
Views: 127
Reputation: 399
Use lineseparator for this
String separator = System.lineSeparator();
display.setText(manu + separator + brand + separator + year + separator + price);
Upvotes: 1
Reputation: 3760
The \n needs to be quoted because it's not a variable, it's a character:
display.setText(manu+"\n"+brand+"\n"+year+"\n"+price);
Having said that, I'm not sure what kind of object display
is, it might not support new lines? What is display
?
Upvotes: 1