VerticalLayout with HorizontalScrollbar


I have a VerticalLayout with a table inside. When there are too many columns to display I would like to have a horizontal scrollbar, but when there are not many columns I would like the table to fill the entire space.

My current code is something like this :

VerticalLayout vl = new VerticalLayout();

this is a Panel .

The current approach only works for when I have many columns but when I have few columns, the table doesn’t fill the entire space available.

Any help is appreciated.

Thank you

You can’t do that on the whole layout; you either have a relative size (100%) or undefined size (as much as is needed). Only undefined sizes are scrollable, and only relative sizes fill up the screen when there is free room.

However, you can set only the table content to scroll by making your VerticalLayout have a relative width: vl.setWidth("100%"); Now the table should create scrollbars itself it there are too many columns to draw. (This works because the table also has a 100% width by default; and has a scrollable content ‘panel’ embedded).