user6676850
user6676850

Reputation: 11

Horizontal scrollbar in vaadin is not appearing

I try to make vaadin view add horizontal scrollbar, but it have no any result. Could you, please, help me. Here is full code of my view:

public class TestView extends CssLayout implements View {
/**
 * 
 */
private static final long serialVersionUID = 1L;

protected void init() {
    Layout content = new VerticalLayout();
    content.setSizeFull();
    addComponent(content);

    // add content to make the scrollbar appear
    HorizontalLayout rightLayout = new HorizontalLayout();
    for (int i = 0; i < 100; i++) {
        rightLayout.addComponent(new Button("Button " + i));
    }

    Panel rightPanel = new Panel(rightLayout);
    rightPanel.setSizeFull();

    content.addComponent(rightPanel);
}

public TestView() {
    super();
    init();
}

@Override
public void enter(ViewChangeEvent event) {
    // TODO Auto-generated method stub

}

}

Upvotes: 0

Views: 624

Answers (2)

Chris M
Chris M

Reputation: 1068

I think you should probably have Extended VerticalLayout rather than CSSLayout, So something like this:

public class TestView extends VerticalLayout implements View {
/**
 * 
 */
private static final long serialVersionUID = 1L;

protected void init() {
    setSizeFull();

    // add content to make the scrollbar appear
    HorizontalLayout rightLayout = new HorizontalLayout();
    for (int i = 0; i < 100; i++) {
        rightLayout.addComponent(new Button("Button " + i));
    }

    Panel rightPanel = new Panel(rightLayout);
    rightPanel.setSizeFull();

    addComponent(rightPanel);
}

public TestView() {
    super();
    init();
}

@Override
public void enter(ViewChangeEvent event) {
    // TODO Auto-generated method stub

}
}

Upvotes: 1

user6676850
user6676850

Reputation: 11

I've add listener and it work fine:

Page.getCurrent().addBrowserWindowResizeListener(event -> {
        setWidth(UI.getCurrent().getPage().getBrowserWindowWidth(), Unit.PIXELS);
        setHeight(UI.getCurrent().getPage().getBrowserWindowHeight(), Unit.PIXELS);
    });

Upvotes: 0

Related Questions