You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridResizeAndScroll.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.vaadin.tests.components.grid;
  2. import java.util.stream.IntStream;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.tests.components.AbstractReindeerTestUI;
  5. import com.vaadin.tests.data.bean.Person;
  6. import com.vaadin.ui.Grid;
  7. import com.vaadin.ui.Grid.SelectionMode;
  8. import com.vaadin.ui.VerticalLayout;
  9. public class GridResizeAndScroll extends AbstractReindeerTestUI {
  10. @Override
  11. protected void setup(VaadinRequest request) {
  12. VerticalLayout content = new VerticalLayout();
  13. addComponent(content);
  14. final Grid<Person> grid = new Grid<>();
  15. content.setHeight("500px");
  16. content.addComponent(grid);
  17. grid.addColumn(Person::getFirstName);
  18. grid.addColumn(Person::getLastName);
  19. grid.addColumn(Person::getEmail);
  20. grid.setItems(IntStream.range(0, 50).mapToObj(this::createPerson));
  21. grid.setSizeFull();
  22. grid.setSelectionMode(SelectionMode.MULTI);
  23. grid.addSelectionListener(event -> {
  24. if (event.getAllSelectedItems().isEmpty()) {
  25. grid.setHeight("100%");
  26. } else {
  27. grid.setHeight("50%");
  28. }
  29. });
  30. }
  31. private Person createPerson(int index) {
  32. Person person = new Person();
  33. person.setFirstName("cell " + index + " 0");
  34. person.setLastName("cell " + index + " 1");
  35. person.setEmail("cell " + index + " 2");
  36. return person;
  37. }
  38. }