Vaadin 8 grid setting column width

Hello,

I am using Vaadin 8.7.0.
I have an editable grid set to 100% width for which I need to configure some of the columns’ width to be exactly defined pixels wide. The other columns should take up the remaining space if there is any left free. I’d expect that using column.setWidth on those specific columns would achieve what I need, but I find that the exact pixel definition is simply ignored, and column width is still getting auto calculated for all columns. The grid itself is in a vertical layout. What am I missing here? I’d appreciate any help, thanks in advance.

Your approach seems valid. I’m not sure why it’s not working for you. The following simple example produces the desired effect:

public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();

        List<Person> personList = new ArrayList<>();
        personList.add(new Person("Lucas", "Kane", 68));
        personList.add(new Person("Peter", "Buchanan", 38));
        personList.add(new Person("Samuel", "Lee", 53));

        Grid<Person> grid = new Grid<>();
        grid.setItems(personList);

        Column<Person, String> firstColumn = grid
                .addColumn(Person::getFirstName).setCaption("First Name");
        grid.addColumn(Person::getLastName).setCaption("Last Name");
        grid.addColumn(Person::getAge).setCaption("Age");

        grid.setWidthFull();
        firstColumn.setWidth(100);

        layout.addComponents(grid);
        setContent(layout);
    }

    class Person {

        private String firstName;
        private String lastName;
        private int age;

        public Person(String firstName, String lastName, int age) {
            setFirstName(firstName);
            setLastName(lastName);
            setAge(age);
        }

        public String getFirstName() {
            return firstName;
        }

        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }

        public String getLastName() {
            return lastName;
        }

        public void setLastName(String lastName) {
            this.lastName = lastName;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

    }


    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }
}

I am using a heavily customized grid, so I tried to reproduce the problem with a really simple example, and it seems to be working as expected. There is something going on with my custom usage scenario specifically, so I need to investigate further.

As it turned out, minimum column widths were set beforehand, and I was trying to set width below the defined minimum. Since javadoc for Column.setWidth states that it overrides minimum width, I was expecting it to work, but it seems that it does not override it after all.