user3702643 user3702643 - 1 year ago 231
Java Question

Alignment in Vaadin

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?


VerticalLayout layout = new VerticalLayout();
VerticalLayout layout1 = new VerticalLayout();
Panel panel = new Panel();

Button button = new Button("Enter");
Button login = new Button("Login");


layout.setComponentAlignment(panel, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(textfield, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(login, Alignment.BOTTOM_CENTER);
layout1.setComponentAlignment(button, Alignment.BOTTOM_CENTER);

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download