Line break within Paragraph in Vaadin23

Viewed 39

I need to place an Article object on my page, that I am creating with Vaadin 23. The article will contain several paragraphs, each one need to be in 3-4 lines of text. I have:

Paragraph p1 = new Paragraph(p11);
p1.add(p12);
p1.add(p13);
Paragraph p2 = new Paragraph(p21);
p2.add(p22)
...
Article article = new Article(p1, p2, ...);

where pNN are Java String instances. I want each of these string to be placed on separate line, but do not want to make them individual paragraphs. Unfortunately, there is no <br> in Vaadin HTML elements. I tried to add '\n' at the end of strings or <br>, but it doesn't work. No line breaks. Does anyone knows how to do it?

1 Answers

Add those \n characters, and then set this CSS property on the paragraph element.

p1.getStyle().set("white-space", "pre-line");
Related