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.

TableHeightWhenHidingHeaders.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.data.Property.ValueChangeEvent;
  3. import com.vaadin.data.Property.ValueChangeListener;
  4. import com.vaadin.tests.components.AbstractTestCase;
  5. import com.vaadin.ui.CheckBox;
  6. import com.vaadin.ui.LegacyWindow;
  7. import com.vaadin.ui.Table;
  8. /**
  9. * Setting table height and setting column header mode as hidden leaves the body
  10. * height of the table as it would be with the headers visible and leaves an
  11. * empty area below the body.
  12. *
  13. */
  14. @SuppressWarnings("serial")
  15. public class TableHeightWhenHidingHeaders extends AbstractTestCase {
  16. @Override
  17. public void init() {
  18. LegacyWindow mainWindow = new LegacyWindow();
  19. setMainWindow(mainWindow);
  20. final Table table = new Table("Test table");
  21. table.addContainerProperty("Name", String.class, null, "Name", null,
  22. null);
  23. table.setItemCaptionPropertyId("Name");
  24. table.setHeight("100px");
  25. table.setImmediate(true);
  26. table.addItem("1").getItemProperty("Name").setValue("Item 1");
  27. table.addItem("2").getItemProperty("Name").setValue("Item 2");
  28. CheckBox showHeaders = new CheckBox("Show headers");
  29. showHeaders.addListener(new ValueChangeListener() {
  30. @Override
  31. public void valueChange(ValueChangeEvent event) {
  32. if ((Boolean) event.getProperty().getValue()) {
  33. // table body height is now 77px, which together
  34. // with header makes 100px
  35. table.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID);
  36. } else {
  37. table.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_HIDDEN);
  38. // header disappears, but table body height stays at
  39. // 77px
  40. // and below the body is an empty area (same height
  41. // as header would
  42. // have)
  43. }
  44. }
  45. });
  46. showHeaders.setValue(true);
  47. showHeaders.setImmediate(true);
  48. mainWindow.addComponent(showHeaders);
  49. mainWindow.addComponent(table);
  50. }
  51. @Override
  52. protected String getDescription() {
  53. // TODO Auto-generated method stub
  54. return null;
  55. }
  56. @Override
  57. protected Integer getTicketNumber() {
  58. return 4507;
  59. }
  60. }