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.

CustomComponentwithUndefinedSize.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.vaadin.tests.components;
  2. import com.vaadin.ui.Button;
  3. import com.vaadin.ui.CustomComponent;
  4. import com.vaadin.ui.Layout;
  5. import com.vaadin.ui.Panel;
  6. import com.vaadin.ui.TabSheet;
  7. import com.vaadin.ui.VerticalLayout;
  8. public class CustomComponentwithUndefinedSize extends TestBase {
  9. @Override
  10. protected String getDescription() {
  11. return "A custom component with no size definition should not prevent scrollbars from being shown when its contents is larger than its parent";
  12. }
  13. @Override
  14. protected Integer getTicketNumber() {
  15. return 2459;
  16. }
  17. @Override
  18. protected void setup() {
  19. TabSheet tabs = new TabSheet();
  20. tabs.setSizeFull();
  21. MyCustomComponent mcc = new MyCustomComponent();
  22. mcc.setSizeUndefined();
  23. // Doesn't work
  24. tabs.addTab(mcc, "Doesn't work (CustomComponent)", null);
  25. // Works:
  26. tabs.addTab(mcc.buildLayout(),
  27. "Works (no CustomComponent, same layout)", null);
  28. addComponent(tabs);
  29. getLayout().setSizeFull();
  30. }
  31. private int step = 0;
  32. public class MyCustomComponent extends CustomComponent {
  33. public MyCustomComponent() {
  34. setCompositionRoot(buildLayout());
  35. }
  36. public Layout buildLayout() {
  37. VerticalLayout layout = new VerticalLayout();
  38. VerticalLayout panelLayout = new VerticalLayout();
  39. panelLayout.setMargin(true);
  40. final Panel widePanel = new Panel("too big", panelLayout);
  41. widePanel.setSizeUndefined();
  42. widePanel.setWidth("2000px");
  43. widePanel.setHeight("200px");
  44. layout.addComponent(widePanel);
  45. Button button = new Button("Change panel size", event -> {
  46. switch (step++ % 4) {
  47. case 0:
  48. widePanel.setWidth("200px");
  49. break;
  50. case 1:
  51. widePanel.setHeight("2000px");
  52. break;
  53. case 2:
  54. widePanel.setWidth("2000px");
  55. break;
  56. case 3:
  57. widePanel.setHeight("200px");
  58. break;
  59. }
  60. });
  61. panelLayout.addComponent(button);
  62. layout.setSizeUndefined();
  63. return layout;
  64. }
  65. }
  66. }