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.

GridScrolledResize.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package com.vaadin.tests.components.grid;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import com.vaadin.server.VaadinRequest;
  5. import com.vaadin.tests.components.AbstractTestUI;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.Grid;
  8. import com.vaadin.ui.HorizontalLayout;
  9. import com.vaadin.ui.Label;
  10. public class GridScrolledResize extends AbstractTestUI {
  11. private Label spaceGrabber;
  12. @Override
  13. public void setup(VaadinRequest vaadinRequest) {
  14. Grid<Person> grid = new Grid<>(Person.class);
  15. grid.setWidth(100, Unit.PERCENTAGE);
  16. grid.setItems(createPersons());
  17. HorizontalLayout splitter = new HorizontalLayout();
  18. splitter.setWidthFull();
  19. splitter.addComponent(grid);
  20. splitter.setExpandRatio(grid, 1f);
  21. addComponent(splitter);
  22. addComponent(new Button("Toggle component", e -> {
  23. if (spaceGrabber == null) {
  24. spaceGrabber = new Label("I'm a space grabber...");
  25. spaceGrabber.setWidth(500, Unit.PIXELS);
  26. }
  27. if (spaceGrabber.isAttached()) {
  28. splitter.removeComponent(spaceGrabber);
  29. } else {
  30. splitter.addComponent(spaceGrabber);
  31. }
  32. }));
  33. }
  34. private List<Person> createPersons() {
  35. ArrayList<Person> people = new ArrayList<>();
  36. for (int i = 0; i < 100; i++) {
  37. people.add(new Person("First", "Last"));
  38. }
  39. return people;
  40. }
  41. public static class Person {
  42. private String fName;
  43. private String lName;
  44. private String col3;
  45. private String col4;
  46. private String col5;
  47. private String col6;
  48. private String col7;
  49. private String col8;
  50. private String col9;
  51. private String col10;
  52. private String col11;
  53. private String col12;
  54. public String getCol8() {
  55. return col8;
  56. }
  57. public void setCol8(String col8) {
  58. this.col8 = col8;
  59. }
  60. public String getCol9() {
  61. return col9;
  62. }
  63. public void setCol9(String col9) {
  64. this.col9 = col9;
  65. }
  66. public String getCol10() {
  67. return col10;
  68. }
  69. public void setCol10(String col10) {
  70. this.col10 = col10;
  71. }
  72. public String getCol11() {
  73. return col11;
  74. }
  75. public void setCol11(String col11) {
  76. this.col11 = col11;
  77. }
  78. public String getCol12() {
  79. return col12;
  80. }
  81. public void setCol12(String col12) {
  82. this.col12 = col12;
  83. }
  84. public Person(String fName, String lName) {
  85. this.fName = fName;
  86. this.lName = lName;
  87. int i = 3;
  88. col3 = fName + " " + lName + i++;
  89. col4 = col3 + i++;
  90. col5 = col3 + i++;
  91. col6 = col3 + i++;
  92. col7 = col3 + i++;
  93. col8 = col3 + i++;
  94. col9 = col3 + i++;
  95. col10 = col3 + i++;
  96. col11 = col3 + i++;
  97. col12 = col3 + i++;
  98. }
  99. public String getfName() {
  100. return fName;
  101. }
  102. public void setfName(String fName) {
  103. this.fName = fName;
  104. }
  105. public String getlName() {
  106. return lName;
  107. }
  108. public void setlName(String lName) {
  109. this.lName = lName;
  110. }
  111. public String getCol3() {
  112. return col3;
  113. }
  114. public void setCol3(String col3) {
  115. this.col3 = col3;
  116. }
  117. public String getCol4() {
  118. return col4;
  119. }
  120. public void setCol4(String col4) {
  121. this.col4 = col4;
  122. }
  123. public String getCol5() {
  124. return col5;
  125. }
  126. public void setCol5(String col5) {
  127. this.col5 = col5;
  128. }
  129. public String getCol6() {
  130. return col6;
  131. }
  132. public void setCol6(String col6) {
  133. this.col6 = col6;
  134. }
  135. public String getCol7() {
  136. return col7;
  137. }
  138. public void setCol7(String col7) {
  139. this.col7 = col7;
  140. }
  141. }
  142. }