我正在使用Vaadin 8创建标题与标签和按钮在右上角。我想显示格式为"Label |Button“的页眉。
问题是我无法将按钮与右角对齐。如果有人能给我一些建议,我将不胜感激。
以下是示例代码片段。
CssLayout menuItemsLayout = new CssLayout();
menuItemsLayout.setPrimaryStyleName("valo-menuitems");
menuItemsLayout.setWidth("100%");
HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.setWidth("100%");
Label headerLbl = new Label(
"Please click on '+' to create a new Note.");
headerLbl.setSizeUndefined();
Label filler1 = new Label(" ");
filler1.setWidth("100%");
Button addNoteHeaderBtn = createAddViewButton("Add Note", "", CommonUiUtils.addIcon);
addNoteHeaderBtn.setStyleName("btnRight");
addNoteHeaderBtn.setSizeUndefined();
horizontalLayout.addComponent(headerLbl);
horizontalLayout.addComponent(filler1);
horizontalLayout.addComponent(addNoteHeaderBtn);
horizontalLayout.setExpandRatio(filler1, 1.3f);
menuItemsLayout.addComponent(horizontalLayout);
mainVerticalLayout.addComponent(menuItemsLayout);
private Button createAddViewButton(final String name, String caption, Resource icon) {
Button button = new Button(caption, new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
}
});
button.setPrimaryStyleName(ValoTheme.MENU_ITEM);
button.setIcon(icon);
return button;}
这是UI的快照。

发布于 2018-08-02 06:36:10
经过大量的尝试和错误,最终修复了以下代码片段的问题
horizontalLayout.setExpandRatio(headerLbl, 1f);
horizontalLayout.setExpandRatio(filler1, 2f);
horizontalLayout.setExpandRatio(addNoteHeaderBtn, 0.15f);以下是修复的快照。

如果您不想要空空间,但希望一个或多个组件占用所有剩余空间。您需要将这样的组件设置为100%大小,并使用setExpandRatio()
https://stackoverflow.com/questions/51642788
复制相似问题