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.

GridLayoutExpandRatio.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.vaadin.tests.components.gridlayout;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractReindeerTestUI;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.GridLayout;
  6. import com.vaadin.ui.HorizontalLayout;
  7. import com.vaadin.ui.Label;
  8. public class GridLayoutExpandRatio extends AbstractReindeerTestUI {
  9. HorizontalLayout layout;
  10. GridLayout gridLayout;
  11. GridLayout gridLayout2;
  12. private static final int ROWS = 5;
  13. private static final int COLS = 5;
  14. private Label[][] labels;
  15. @Override
  16. protected void setup(VaadinRequest request) {
  17. labels = new Label[ROWS][COLS];
  18. layout = new HorizontalLayout();
  19. gridLayout = new GridLayout(ROWS, COLS);
  20. gridLayout.setHideEmptyRowsAndColumns(true);
  21. gridLayout2 = new GridLayout(4, 4);
  22. gridLayout2.setHideEmptyRowsAndColumns(true);
  23. for (int i = 0; i < ROWS; i++) {
  24. for (int j = 0; j < COLS; j++) {
  25. Label label = new Label("Slot " + i + " " + j);
  26. labels[i][j] = label;
  27. gridLayout.addComponent(label, j, i);
  28. if (!(i == 2 || j == 2)) {
  29. Label label2 = new Label("Slot " + i + " " + j);
  30. gridLayout2.addComponent(label2);
  31. }
  32. }
  33. }
  34. gridLayout.setHeight("500px");
  35. gridLayout.setWidth("500px");
  36. gridLayout.setSpacing(true);
  37. gridLayout2.setHeight("500px");
  38. gridLayout2.setWidth("500px");
  39. gridLayout2.setSpacing(true);
  40. addComponent(layout);
  41. HorizontalLayout space = new HorizontalLayout();
  42. space.setWidth("100px");
  43. layout.addComponent(gridLayout);
  44. layout.addComponent(space);
  45. layout.addComponent(gridLayout2);
  46. setExpandRatio();
  47. addComponent(new Button("Hide/show both middle Column and row",
  48. event -> hideComponetns()));
  49. }
  50. private void hideComponetns() {
  51. for (int i = 0; i < ROWS; i++) {
  52. for (int j = 0; j < COLS; j++) {
  53. if (i == 2 || j == 2) {
  54. if (labels[i][j].isVisible()) {
  55. labels[i][j].setVisible(false);
  56. } else {
  57. labels[i][j].setVisible(true);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. private void setExpandRatio() {
  64. gridLayout.setRowExpandRatio(2, 5);
  65. gridLayout2.setRowExpandRatio(1, 5);
  66. }
  67. @Override
  68. protected Integer getTicketNumber() {
  69. return 8855;
  70. }
  71. @Override
  72. protected String getTestDescription() {
  73. return "If row/column doesn't have elements but have an expand ratio set, it should be shown as a empty row/column";
  74. }
  75. }