首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Vaadin 8水平布局,带标签和按钮

Vaadin 8水平布局,带标签和按钮
EN

Stack Overflow用户
提问于 2018-08-02 05:55:01
回答 1查看 550关注 0票数 2

我正在使用Vaadin 8创建标题与标签和按钮在右上角。我想显示格式为"Label |Button“的页眉。

问题是我无法将按钮与右角对齐。如果有人能给我一些建议,我将不胜感激。

以下是示例代码片段。

代码语言:javascript
复制
    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的快照。

EN

回答 1

Stack Overflow用户

发布于 2018-08-02 06:36:10

经过大量的尝试和错误,最终修复了以下代码片段的问题

代码语言:javascript
复制
    horizontalLayout.setExpandRatio(headerLbl, 1f);
    horizontalLayout.setExpandRatio(filler1, 2f);
    horizontalLayout.setExpandRatio(addNoteHeaderBtn, 0.15f);

以下是修复的快照。

如果您不想要空空间,但希望一个或多个组件占用所有剩余空间。您需要将这样的组件设置为100%大小,并使用setExpandRatio()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51642788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档