Reputation: 2090
I have a Vaadin (7.6.6) grid to show some java beans, which is in a layout
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.setMargin(true);
List<Booster> boosters = new ArrayList<>();
boosters.add(creaBoost("e"));
boosters.add(creaBoost("f"));
boosters.add(creaBoost("g"));
Grid grid = new Grid();
grid.setContainerDataSource(new BeanItemContainer<>(Booster.class, boosters));
grid.setWidth("80%");
grid.setSelectionMode(SelectionMode.MULTI);
grid.removeColumn("ident");
layout.addComponent(grid);
Button button = new Button("Delete", FontAwesome.WARNING);
button.setStyleName(ValoTheme.BUTTON_DANGER);
layout.addComponent(button);
which results in the following
I was wondering, where this height came from ? Is there a way to reduce it and only show the actual height it requires ?
Ideally it takes into account to not get higher than X, so that if more elements are part of the grid, it does not grow constantly ?
How can this be achieved ?
Upvotes: 0
Views: 97
Reputation: 523
You can use the following to functions (setHeightMode, setHeightByRows) to define the height by interpreting the quantity of the grid-elements or set it to a specific amount of visible rows.
Grid myGrid = new Grid();
VerticalLayout test = new VerticalLayout();
Bill testBill = new Bill(23, "Test", "Products", 3, new Date(), new Date());
BeanItemContainer<Bill> testItemContainer = new BeanItemContainer<Bill>(Bill.class);
testItemContainer.addItem(testBill);
myGrid.setContainerDataSource(testItemContainer);
test.addComponent(myGrid);
myGrid.setHeightMode(HeightMode.ROW);
myGrid.setHeightByRows(testItemContainer.size());
Upvotes: 1