Time for action – using panels

Let's add a panel using our framework application.

  1. In LayoutFrameworkUI class, add a getPanel method and call it from the init method to add the returned component to our main layout:
    public class LayoutFrameworkUI extends UI {
      
      protected void init(VaadinRequest request) {
    
        ...
    
        layout.addMenuOption("Panel", getPanel());
      }
    
      ...
    
      private Panel getPanel() {
        String someNumbers = "";
    
        for (int i = 0; i < 2000; i++) {
          someNumbers += " " + i;
        }
    
        Label content = new Label(someNumbers);
        Panel panel = new Panel("Panel's caption", content);
        panel.setWidth("200px");
        panel.setHeight("100px");
        panel.setScrollTop(3000); // pixels from top
    
        return panel;
      }
    
    }
  2. Run it!

What just happened?

Here is a screenshot of the application showing ...

Get Vaadin 7 UI Design By Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.