我在Vaadin中编写了以下代码.
问题是对齐不起作用.我将它设置为bottom_center,但组件都粘贴在我的Web浏览器的顶部(top_center).
任何人都可以帮我解决这个问题吗?
谢谢!
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);
Run Code Online (Sandbox Code Playgroud)
组件正在与顶部对齐的原因是您没有为VerticalLayouts指定高度.如果未指定布局的大小,则其大小由其包含的子组件确定.在这种情况下,设置对齐将没有任何区别,因为布局的插槽内没有额外的空间.
设置大小,使用例如layout.setHeight("100%");或layout.setSizeFull();,你应该立即注意到差异.