-1

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);
    }

But I am able to increase the width of the columns based on the content

Ravi Makwana
  • 2,782
  • 1
  • 29
  • 41
nayansFosgit
  • 69
  • 1
  • 7

2 Answers2

1

You are setting your Grid to be full width. In Vaadin 8 that means that Grid should be occupying the full size of the slot in the layout where it is. Say that you have a Grid in VerticalLayout whose width is "100px", and you set the Grid to be full width, it will be "100px" wide. I see that you have your Grid in some parent layout, that may be in some grand parent layout, etc. You need to follow that chain that there is right width set there too.

Check also Layouting basics training video.

Tatu Lund
  • 9,949
  • 1
  • 12
  • 26
0

at the end of MyTabbedForm constructor try adding the following lines

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

This will set width 100% to all the ancestors of the grid.

tremendous7
  • 721
  • 6
  • 9