Hallo all,

I have the requirement to implement a layout, where the main application panel is centered in the browser window, has fixed width (800px) and the height must fit the window's height. When the browser window width is smaller than 800px, the horizontal scrollbar should appear. Analogically, when the window height is smaller than 500px, vertical scrollbar should appear.

I’ve implemented the following code, which fulfills the requirement for horizontal scrollbar. Unfortunately it doesn’t work for vertical one.

Do you have any idea, how should I change the code to enable vertical scrollbar, when the window is smaller than 500px?

Code:
public class MainDialog extends Viewport {
    private LayoutContainer mainPanel = new LayoutContainer(new BorderLayout());


    public MainDialog() {
        setLayout(new VBoxLayout(VBoxLayoutAlign.CENTER));
        setScrollMode(Scroll.AUTO);


        mainPanel.setWidth(800);
        mainPanel.setHeight(500);
        mainPanel.setBorders(true);


        addWidgetsToMainPanel();


        VBoxLayoutData vbld_mainPanel = new VBoxLayoutData();
        vbld_mainPanel.setFlex(1.0);
        add(mainPanel, vbld_mainPanel);
    }


    private void addWidgetsToMainPanel() {
        LayoutContainer headerPanel = new LayoutContainer(new FitLayout());
        headerPanel.setBorders(true);
        headerPanel.add(new Text("Header"));
        mainPanel.add(headerPanel, new BorderLayoutData(LayoutRegion.NORTH, 100.0f));


        LayoutContainer contentPanel = new LayoutContainer(new FitLayout());
        contentPanel.setBorders(true);
        contentPanel.add(new Text("page content"));
        mainPanel.add(contentPanel, new BorderLayoutData(LayoutRegion.CENTER));
    }
}

Best regards,
Adam Sas