【发布时间】:2014-02-14 11:27:48
【问题描述】:
我正在寻找一种在我的 VerticalLayout 中创建页脚的方法。 有一些方法可以用 VerticalLayout 创建页脚吗?
有什么想法吗?
【问题讨论】:
标签: java frameworks vaadin vaadin7
我正在寻找一种在我的 VerticalLayout 中创建页脚的方法。 有一些方法可以用 VerticalLayout 创建页脚吗?
有什么想法吗?
【问题讨论】:
标签: java frameworks vaadin vaadin7
这取决于页脚的含义, 但最简单的方法是添加一个 HorizontalLayout 作为 VerticalLayout 中的最后一个元素。
只需确保 VerticalLayout 中的其他组件设置为由容器扩展即可。 (在 VerticalLayout 组件中查找 setExpandRatio(...)。
【讨论】:
一个简单的解决方案。 André Schild 已经提供了宝贵的意见。
VerticalLayout vlMain = new VerticalLayout();
vlMain.setSizeFull();
HorizontalLayout hlFooter = new HorizontalLayout();
hlFooter.setHeight("50px"); // if you want you can define a height.
hlFooter.addComponent(new Label("Test1")); // adding a simple component. You might want to set alignment for that component
vlMain.addComponent(mainComponent);
vlMain.setExpandRatio(mainComponent, 1.0f); // "give" the main component the maximum available space
vlMain.addComponent(hlFooter);
【讨论】:
现在我解决了我的问题,我做到了并且工作正常。
public class PrincipalLayout extends VerticalLayout{
private HorizontalLayout header, center, footer;
public PrincipalLayout(){
setSizeFull();
initComponents();
defineLayout();
}
private void initComponents(){
header = new HorizontalLayout();
center = new HorizontalLayout();
footer = new HorizontalLayout();
header.addComponent(new Label("HEADER"));
center.addComponent(new Label("CENTER"));
footer.addComponent(new Label("FOOTER"));
}
private void defineLayout(){
addComponent(header);
addComponent(center);
addComponent(footer);
setExpandRatio(center, 1.0f);
}
}
【讨论】: