Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

long text inside a Label element

ruz default
1 decade ago Mar 09, 2010 9:31am


i'm quite new to vaadin, so i have a question.

i have a 2x1 grid layout containing the following data: the first column contains an image and the second one contains vertical layout with the details fields of the image.

here is the code:

GridLayout dgl = new GridLayout(2, 1);
 Label img_full = new Label("<img src='"+m.getPoster_big()+"'>");
 dgl.addComponent(img_full, 0,0);
 VerticalLayout descr = new VerticalLayout();
 descr.addComponent(new Label("Year: "+m.getFilmYear()));
 descr.addComponent(new Label("Description: "+m.getDescription()));

 dgl.addComponent(descr, 1, 0);

where m is a bean and details is a window.

the problem is that if the length of description text exceeds the width of the grid row, it appears as a single line of text coming out of the window bounds.

maybe someone knows what's the problem?


Jouni Koivuviita
1 decade ago Mar 09, 2010 11:49am

My first guess is that you need to specify an explicit width for the GridLayout. Since Labels are by default 100% wide, they should wrap, but if the Label is placed inside an undefined wide layout, the Labels default width is reduced to undefined as well (since that's what 100% of undefined is), making it stick to one line (nowrap).

So try GridLayout.setWidth("400px") or GridLayout.setWidth("100%") for instance.

If setting the width is out of the question, another workaround then is to override the "white-space: nowrap" setting with CSS. You need to add a style name (and a custom theme, too) for the Label in order to do that:

// Java

// CSS
.v-label-wrap {
    white-space: normal;
ruz default
1 decade ago Mar 09, 2010 12:44pm
Niyas Manzoor
1 decade ago Jun 29, 2010 4:17pm
Niyas Manzoor
1 decade ago Jun 29, 2010 4:30pm
Thomas Kiesl
5 years ago Oct 02, 2017 9:59am
Thomas Kiesl
5 years ago Oct 06, 2017 11:07am