Search code examples
layoutvaadinwindow-resizevaadin8

Vaadin 8 View: No horizontal scrollbar on window resizing


I have a Vaadin 8 application with several views.

public class ViewName extends Panel implements View {

There is a VerticalLayout as main layout in the panel.

public ViewName() {
    setSizeFull();
    VerticalLayout mainLayout = new VerticalLayout();
    setContent(mainLayout);

Then I have many different layouts (HorizontalLayout, GridLayout) or Components such as Label being added as components to the mainLayout. For the HorizontalLayouts I often do the following to use the full width of the screen:

hLayout.setWidth("100%");

I have a lot of icons, grids etc. Everything is OK as long as I don't resize the window. When I resize the window to a small size I get a mess (icons, text etc. on top of each other) and no horizontal scrollbar. (However, the grids get horizontal scrollbars.) I have tried many things to fix this. If I add

mainLayout.setSizeFull();

or

mainLayout.setWidth("100%");

I have a mess on the big screen already. I also tried the CSS for the mainLayout as described here. I get several scrollbars but none for the window itself!

The only component that resizes correctly is a Label added to the mainLayout, e.g.:

Label title = new Label("Some text",ContentMode.HTML);
    title.setWidth(100, Unit.PERCENTAGE);
    mainLayout.addComponent(title);
    mainLayout.setComponentAlignment(title, Alignment.MIDDLE_CENTER);

I also noticed that anything in a GridLayout seems to stay in place after resizing but is not vissible since I have no scrollbar. However, icons in a HorizontalLayout get on top of each other.

What is wrong? Please, I need a general instruction on which layout I should use as main layout for my view panel, how to size the components and how to get ONE horizontal scrollbar for the main window if necessary.


Solution

  • The problem is that you are setting the width of your mainLayout to the width of your view. This means, that your mainLayouts width will never be bigger than your views width. So no scroll bar will appear.

    According to the information you posted, changing your mainLayouts width to undefined should fix the problem.

     mainLayout.setWidth("-1px");