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.7KB

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