Reputation: 1495
I have the following piece of code that I wrote in Vaadin.
The problem is that the alignment does not work. I set it to bottom_center, but the components are all stuck to the top (top_center) of my web browser.
Can anyone help me out with this?
Thanks!
VerticalLayout layout = new VerticalLayout();
VerticalLayout layout1 = new VerticalLayout();
Panel panel = new Panel();
panel.setWidth("500px");
panel.setHeight("300px");
Button button = new Button("Enter");
Button login = new Button("Login");
layout1.addComponent(textfield);
layout1.addComponent(button);
layout1.addComponent(login);
layout.addComponent(panel);
layout.setComponentAlignment(panel, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(textfield, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(login, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(button, Alignment.BOTTOM_CENTER);
Upvotes: 2
Views: 7284
Reputation: 39
you mus set setSizeUndefined() to your panel, textfield, login, button component and setSizeFull layout1.
Upvotes: -1
Reputation: 1035
The reason for the components appering to be aligned to the top is that you haven't specified a height for your VerticalLayouts. When you don't specify a size for a layout, its size is determined by the child components it contains. In such a case, setting the alignment won't make any difference, as there's no extra room inside the layout's slots.
Set the size, using e.g. layout.setHeight("100%");
or layout.setSizeFull();
and you should notice the difference immediately.
Upvotes: 8
Reputation: 15508
You did not specify a height for the layout so it'll expand from the top towards the bottom as it needs with each component you add. If you set layout.setHeight("100%");
the components will be aligned at the bottom.
Upvotes: 1