UI, Window, and Panel Content

The UI, Window, and Panel all have a single content component, which you need to set with setContent(). The content is usually a layout component, although any component is allowed.

Java

  1. Panel panel = new Panel("This is a Panel");
  2. VerticalLayout panelContent = new VerticalLayout();
  3. panelContent.addComponent(new Label("Hello!"));
  4. panel.setContent(panelContent);
  5. // Set the panel as the content of the UI
  6. setContent(panel);

The size of the content is the default size of the particular layout component, for example, a VerticalLayout has 100% width and undefined height by default (this coincides with the defaults for Panel and Label). If such a layout with undefined height grows higher than the browser window, it will flow out of the view and scrollbars will appear. In many applications, you want to use the full area of the browser view. Setting the components contained inside the content layout to full size is not enough, and would actually lead to an invalid state if the height of the content layout is undefined.

Java

  1. // First set the root content for the UI
  2. VerticalLayout content = new VerticalLayout();
  3. setContent(content);
  4. // Set the content size to full width and height
  5. content.setSizeFull();
  6. // Add a title area on top of the screen. This takes
  7. // just the vertical space it needs.
  8. content.addComponent(new Label("My Application"));
  9. // Add a menu-view area that takes rest of vertical space
  10. HorizontalLayout menuview = new HorizontalLayout();
  11. menuview.setSizeFull();
  12. content.addComponent(menuview);

See “Layout Size” for more information about setting layout sizes.