- Vaadin 7 UI Design By Example:Beginner’s Guide
- Alejandro Duarte
- 271字
- 2021-08-13 16:17:43
Time for action – the main layout
Let's start by coding the main layout using our well known friend VerticalLayout
and the new guy HorizontalLayout
:
- Create a new Vaadin project. For this example, we will use layout-framework as project name and
LayoutFrameworkUI
as the UI class. - Create a new Java class
MainLayout
. - Let
MainLayout
extendVerticalLayout
:public class MainLayout extends VerticalLayout { }
- Add layouts for upper and lower sections of
MainLayout
:public class MainLayout extends VerticalLayout { private VerticalLayout upperSection = new VerticalLayout(); private HorizontalLayout lowerSection = new HorizontalLayout(); private VerticalLayout menuLayout = new VerticalLayout(); private VerticalLayout contentLayout = new VerticalLayout(); }
- Add the following default constructor for
MainLayout
:public MainLayout() { upperSection.addComponent(new Label("Header")); menuSection.addComponent(new Label("Menu")); contentSection.addComponent(new Label("Content")); lowerSection.addComponent(menuLayout); upperSection.addComponent(contentLayout); addComponent(upperSection); addComponent(lowerSection); }
- Change the
init
method in yourLayoutFrameworkUI
class to match this:public class LayoutFrameworkUI extends UI { protected void init(VaadinRequest request) { setContent(new MainLayout()); } }
- Compile, deploy, and run your application.
What just happened?
Let's get real; the application doesn't look very impressive so far:

We have created our very own layout class taking advantage of VerticalLayout
. So our MainLayout
is a VerticalLayout
too, but now it contains a VerticalLayout
for the header or upper section and a HorizontalLayout
for the lower section which in turn contains a menu layout and a content layout, both using VerticalLayout
. Layout, layout, layout, what a tongue-twister!
We have added some labels to see how our layout works.
Note
Note that when we add components into a HorizontalLayout
they are placed from left to right.
Take a look at the components tree for MainLayout
(we are showing only layout components):

- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- 計算機圖形學編程(使用OpenGL和C++)(第2版)
- Boost C++ Application Development Cookbook(Second Edition)
- Microsoft Application Virtualization Cookbook
- Hands-On C++ Game Animation Programming
- ASP.NET 3.5程序設計與項目實踐
- Mastering Google App Engine
- HDInsight Essentials(Second Edition)
- Laravel Application Development Blueprints
- Fastdata Processing with Spark
- Apache Solr PHP Integration
- OpenCV Android開發實戰
- Drupal 8 Development:Beginner's Guide(Second Edition)
- Visual Basic程序設計基礎
- ASP.NET開發寶典