com.vaadin.flow.component.formlayout.

Class FormLayout.FormRow

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.formlayout.FormLayout.FormRow

All Implemented Interfaces:

AttachNotifier, DetachNotifier, HasComponents, HasElement, HasEnabled, HasStyle, Serializable

Enclosing class:

FormLayout

@Tag("vaadin-form-row") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.8.2") @NpmPackage(value="@vaadin/form-layout",version="24.8.2") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/form-layout/src/vaadin-form-row.js") public static class FormLayout.FormRow extends Component implements HasComponents

Server-side component for the <vaadin-form-row> element. Used to arrange fields into rows inside a FormLayout when auto-responsive mode is enabled.

Each FormRow always starts on a new row. Fields that exceed the available columns wrap to a new row, which then remains reserved exclusively for the fields of that FormRow.

Example of creating a FormRow with two fields and a single field that spans two columns:

 FormLayout formLayout = new FormLayout();
 formLayout.setAutoResponsive(true);

 FormRow firstRow = new FormRow();
 firstRow.add(new TextField("First name"), new TextField("Last name"));

 FormRow secondRow = new FormRow();
 secondRow.add(new TextArea("Address"), 2); // colspan 2

 formLayout.add(firstRow, secondRow);
 

Author:

Vaadin Ltd

See Also:

  • Constructor Details

  • Method Details

    • add

      public void add(Component component, int colspan)

      Adds a component with the desired colspan. This method is a shorthand for calling HasComponents.add(Component...) and setColspan(Component, int)

      Parameters:

      component - the component to add

      colspan - the desired colspan for the component

    • setColspan

      public void setColspan(Component component, int colspan)

      Sets the colspan of the given component's element. Will default to 1 if an integer lower than 1 is supplied. You can directly add components with the wanted colspan with add(Component, int).

      Parameters:

      component - the component to set the colspan for, not null

      colspan - the desired colspan for the component

    • getColspan

      public int getColspan(Component component)

      Gets the colspan of the given component. If none is set, returns 1.

      Parameters:

      component - the component whose colspan is retrieved

      Returns:

      the colspan of the given component or 1 if none is set

    • addFormItem

      public FormLayout.FormItem addFormItem(Component field, String label)

      Creates a new FormLayout.FormItem with the given component and the label string, and adds it to the form row. The label is inserted into the form item as a NativeLabel.

      Parameters:

      field - the field component to be wrapped in a form item

      label - the label text to be displayed

      Returns:

      the created form item

    • addFormItem

      public FormLayout.FormItem addFormItem(Component field, Component label)

      Creates a new FormLayout.FormItem with the given field and label components and adds it to the form row.

      Parameters:

      field - the field component to be wrapped in a form item

      label - the label component to be displayed

      Returns:

      the created form item