Search code examples
javagridvaadin

Vaadin 24: most simple Grid does not display in VerticalLayout


I'm new to vaadin and I currently explore vaadin 24. Why is this simple grid not displayed?

public class MainView extends VerticalLayout {
    public MainView() {
        Grid<String> grid = new Grid<>();
        grid.setSizeFull();
        grid.addColumn(s->s);
        grid.setItems("foo");
        add(grid);
    }

This question was asked long time ago, but I could not find a working solution. In firefox and edge the grid is displayed as a horizontal line. I already tried setSizeFull() for the containing VerticalLayout (not shown in the code above) and to "wrap" the grid into a Div. What am I missing?


Solution

  • The problem is, as you mentioned, that the VerticalLayout has no height.

    This works for me:

    public class MainView extends VerticalLayout {
    
        public MainView () {
            setHeightFull();
    
            Grid<String> grid = new Grid<>();
            grid.setSizeFull();
            grid.addColumn(s -> s);
            grid.setItems("foo");
            add(grid);
        }