Reputation: 1
I want to add text to new line.
My code:
TextField text = new TextField();
TextArea area = new Area();
String txt = text.getValue().toString();
area.setValue("\n" + txt);
When I click in my button I see my value from TextField. I want new text in new line in TextArea. Please help.
Upvotes: 0
Views: 3519
Reputation: 754
Keep in mind that Vaadin works with browsers, so normal scape characters doesn't work, ie: you cannot use '\n' on normal Label
. Instead of it do the following:
label.setCaptionAsHtml(true);
label.setValue(label.getValue()+"<br>");
If you are using a TextArea
, you can use '\n'
as usual.
In case of TextFiel
, you cannot write multiple lines, as it would convert it in a TextArea
and this behavior is deprecated.
Upvotes: 0
Reputation: 63
I recommend to add the new line at the end. You will avoid having an empty line at the beginning in your TextArea.
E.g. outputTextArea.setValue(outputTextArea.getValue() + input.getValue() + "\n");
Furthermore: Make sure to use a TextArea and not a TextField, because line breaks with "\n" won't work in TextField!
Upvotes: 0
Reputation: 3180
Instead of
area.setValue("\n" + txt);
Use
area.setValue(area.getValue + "\n" + txt);
This will ADD text, not REPLACE
Upvotes: 0
Reputation: 37008
You have to append that new value to the existing one and set that. Something along the lines of:
area.setValue(area.getValue() + "\n" + txt);
The Vaadin TextArea has no direct way to append. Also the rules in java, when to use +
for stringsapply. Consider using a StringBuffer
, if you do this alot.
Upvotes: 1