I have an incoming text string that contains a line break ("\r").
When I output it with : System.out.println(myString)
, the carriage return is interpreted.
However, when I set the string as the Label's content, it ignores the carriage return.
How can I force the Label to interpret the carriage/line return (without the XHTML mode) ?
This is how you can put this text into your label:
@Override
public void init() {
Window window = new Window();
Label label = new Label("<pre>First line\rSecond line\nThird line</pre>", Label.CONTENT_XHTML);
window.addComponent(label);
setMainWindow(window);
}
The key is using Label.CONTENT_XHTML content mode and enclosing the text inside a <pre>
tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With