【问题标题】:Unable to increase the width of Grid in Vaadin 8无法在 Vaadin 8 中增加 Grid 的宽度
【发布时间】:2021-03-19 08:36:23
【问题描述】:

public MyTabbedForm() {
        this.refresh = new Button("");
        this.refresh.addClickListener(buttonClickEvent -> {
            this.grid.setItems(getCompany());
   
        });
        this.grid = new Grid<>();
        this.grid.setWidthFull();
        this.grid.addColumn(Company::getName).setHeader("Name");
        this.grid.addColumn(company -> (company. getCompanyCode()))
                .setHeader("Company Code");
        this.grid.addColumn(company -> (company. getCompanyId()))
        .setHeader("Company Id");
        this.grid.addColumn(company -> (company. getCompanyStatus()))
        .setHeader("Company Status");
        this.grid.getColumns().forEach(col -> col.setAutoWidth(true));
        add(this.refresh,this.grid);
    }

但我可以根据内容增加列的宽度

【问题讨论】:

    标签: java vaadin vaadin7 vaadin8


    【解决方案1】:

    您将Grid 设置为全角。在 Vaadin 8 中,这意味着 Grid 应该占据布局中插槽的全部大小。假设您在VerticalLayout 中有一个宽度为“100px”的网格,并且您将Grid 设置为全宽,它将是“100px”宽。我看到您的 Grid 在某些父布局中,可能在某些祖父布局中,等等。您需要遵循该链,那里也设置了正确的宽度。

    还可以查看Layouting basics 培训视频。

    【讨论】:

      【解决方案2】:

      在 MyTabbedForm 构造函数的末尾尝试添加以下行

          Component parent = this.grid.getParent();
          while (null != parent) {
              if (parent instanceof AbstractComponent) {
                  parent.setWidthFull();
              }
              parent = getParent();
          }
      

      这将为网格的所有祖先设置宽度 100%。

      【讨论】:

        猜你喜欢
        • 2014-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多