Panel scrollbars

Hi!
I ‘need’, ok, joke, but anyway, I would like to have bottom scrollbars on panel. So I have to panels, the other is added to the first one, and the second panel is much bigger. But I get only scrollbars on the right. But no scrollbars on bottom.
What I’m doing wrong?

Window mainWindow = new Window("MyApp");
mainWindow.setScrollable(true);
setMainWindow(mainWindow);

Panel panel = new Panel("Panel");
panel.setScrollable(true);
panel.setWidth("300px");
panel.setHeight("300px");	

Panel panel2 = new Panel("InnerPanel");
panel2.setWidth("2000px");
panel2.setHeight("1000px");
panel.addComponent(panel2);

mainWindow.addComponent(panel);

thnx,
Janez

Hi,

What you are missing is a gotcha in the Vaadin framework. A Panel by default contains a ComponentContainer (this can be a layout, a Panel or some other ComponentContainer). By default, if you do not specify any component container using the new Panel(String,ComponentContainer) constructor the Panel will contain a VerticalLayout. This means that in your case you actually have a hierarchy like Panel → VerticalLayout → Panel and you will not get scrollbars as scrollbars do not appear in a layout.

There are (at least) two ways you can do:

  • use the Panel(String,ComponentContainer) constructor or use panel.setContent() instead of panel.addComponent for your second Panel.
  • set the size of the verticallayout to be undefined so it will be sized according to the inner panel

Yep, usually this is fixed by adding the following (as suggested by Mr. Anonymous):

panel.getContent().setSizeUndefined();

Which basically causes the default VerticalLayout inside the first panel to be sized by it’s content and not by it’s parent.

/Jonatan

Thank you Jonatan and thank you Anonymous for explanation.
It works!
Janez