Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin : My label ignores the carriage return character

Tags:

label

vaadin

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) ?

like image 224
Tara Avatar asked Jan 11 '12 10:01

Tara


1 Answers

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.

like image 52
n0rm1e Avatar answered Sep 21 '22 09:09

n0rm1e