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.

ColumnExpandRatio.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package com.vaadin.tests.components.table;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.ui.Label;
  4. import com.vaadin.v7.data.Item;
  5. import com.vaadin.v7.data.util.IndexedContainer;
  6. import com.vaadin.v7.ui.Table;
  7. public class ColumnExpandRatio extends TestBase {
  8. @Override
  9. protected String getDescription() {
  10. return "Column expand ratios can be used to adjust the way "
  11. + "how excess horizontal space is divided among columns.";
  12. }
  13. @Override
  14. protected Integer getTicketNumber() {
  15. return 2806;
  16. }
  17. private static final int ROWS = 100;
  18. @Override
  19. public void setup() {
  20. Table table1 = initTable();
  21. addComponent(new Label("Plain table"));
  22. addComponent(table1);
  23. }
  24. private Table initTable() {
  25. Table table = new Table();
  26. table.setWidth("100%");
  27. IndexedContainer idx = new IndexedContainer();
  28. idx.addContainerProperty("firstname", String.class, null);
  29. idx.addContainerProperty("lastname", String.class, null);
  30. Item i = idx.addItem(1);
  31. i.getItemProperty("firstname").setValue("John");
  32. i.getItemProperty("lastname").setValue("Johnson");
  33. i = idx.addItem(2);
  34. i.getItemProperty("firstname").setValue("Jane");
  35. i.getItemProperty("lastname").setValue("Janeine");
  36. for (int index = 3; index < ROWS; index++) {
  37. i = idx.addItem(index);
  38. i.getItemProperty("firstname").setValue("Jane");
  39. i.getItemProperty("lastname").setValue("Janeine");
  40. }
  41. idx.addContainerProperty("fixed 50px column", String.class, "");
  42. idx.addContainerProperty("Expanded with 2", String.class, "foobar");
  43. table.setContainerDataSource(idx);
  44. table.setColumnHeader("firstname", "FirstName");
  45. table.setColumnHeader("lastname", "LastName (1)");
  46. table.setColumnWidth("fixed 50px column", 50);
  47. table.setColumnExpandRatio("Expanded with 2", 2);
  48. table.setColumnExpandRatio("lastname", 1);
  49. return table;
  50. }
  51. }