Layouts doesn’t support scrollbars, but panels do, so create a extra panel, add the layout to it, and put the panel there where you put the layout earlier. Use panel.setSizeFull() too.
A quite common Vaadin gotcha. A Panel by default contains a VerticalLayout (width: 100%) which will prevent this from working. Replace this verticallayout by your horizontallayout using panel.setContent(hl); instead of panel.addComponent(hl). Another option is to make sure the verticallayout is undefined wide (i.e. will grow with content) by saying panel.getContent().setSizeUndefined() but then you will have an unnecessary layout in your application.
This still does not work for me when I try to get vertical and horizontal scroll bars on my GridLayout (or actually on the Panel containing it.) Here is a synopsis of pertinent code:
// container panel for scrolling
Panel p = new Panel();
p.setStyle(Panel.STYLE_LIGHT);
p.setScrollable(true);
p.setSizeFull();
// main form area
GridLayout formArea = new GridLayout(8, 10);
formArea.setSizeUndefined();
// components are added to the GridLayout here
....
// add form to layout
p.setContent(formArea);
The scrollbars never show up regardless of the width and height of the contents or the browser window. What may I be missing?
EDIT: I resolved my issue. I forgot to mention the Panel is itself inside a HorizontalLayout. I had to setSizeFull() on the HorizontalLayout, then also had to call horLayout.setExpandRatio(p, 1f) and setExpandRatio(horLayout, 1f) on the parent object which is a VerticalLayout. Then it all looks good and appears to work.
I am also facing the same problem when adding Horizontal layout containing the table, the horizontal layout is added in panel but no scroll bars getting added.
Panel tablePanel = new Panel(); // Using panel to have a horizontal scroll bar for inside table.
table.setPageLength(sample.getAnalysisList().size());
table.setStyleName(“innerDataTable”);
table.setSizeFull();
HorizontalLayout hr = new HorizontalLayout();
hr.setSizeUndefined();
hr.addComponent(table);
tablePanel.setContent(hr);
tablePanel.setScrollable(true);
tablePanel.setSizeFull();
Hi i have created 4 gridlayout inside a vertical layout.
3 grids have less no of columns bt 1 grid has large no of column so i am not able to see all the columns.
I want horizontal scrollbar for that prticular layout.
i have already added scrollbar to panel bt it’s showing only vertical scroll bar not horizontal.
VerticalLayouts have a default width of 100%.
So something like this:
((VerticalLayout) panel.getContent()).setSizeUndefined();
might fix your problem.