Creating a simple form
When we need to pass data from the user to the server, we use input fields. When we have more fields, we arrange them into forms. Creating forms in Vaadin is very easy. In this recipe, we will create a simple login form panel as shown in the following screenshot:
How to do it...
Carry out the following steps to create a simple login form:
We create a Vaadin project with a main UI class named
Demo
.public class Demo extends UI {…}
Our form will be wrapped in the
Panel
container. Therefore, we create aLoginFormPanel
class that extends thePanel
class.public class LoginFormPanel extends Panel {…}
All the parts of the form lie in the constructor. First, we set the name and size of the form.
public LoginFormPanel() { super("Login"); setSizeUndefined(); …
We will use
FormLayout
for the fields. In this layout, captions are rendered to the left of their respective components. Margintop
and marginbottom
are by default set totrue
. Through thesetMargin(true)
method...