FormLayout is the default layout of a Form component. It lays the form fields and their captions out in two columns, with optional indicators for required fields and errors that can be shown for each field.

A Form handles additional layout elements itself, including a caption, a form description, a form error indicator, a footer that is often used for buttons and a border. For more information on these, see Section 5.19, “Form.

The field captions can have an icon in addition to the text.

// A FormLayout used outside the context of a Form
FormLayout fl = new FormLayout();

// Make the FormLayout shrink to its contents 
fl.setSizeUndefined();

TextField tf = new TextField("A Field");
fl.addComponent(tf);

// Mark the first field as required
tf.setRequired(true);
tf.setRequiredError("The Field may not be empty.");

TextField tf2 = new TextField("Another Field");
fl.addComponent(tf2);

// Set the second field straing to error state with a message.
tf2.setComponentError(
    new UserError("This is the error indicator of a Field."));

The resulting layout will look as follows. The error message shows in a tooptip when you hover the mouse pointer over the error indicator.