Why use vaadin form layout if you can use a combination of vaadin horizonta

Hi everyone,

Yesterday I saw someone making a form using horizontal and vertical layout. It seems to work easier/faster then working with the vaadin form layout to me.
Is there any rule/benefit for using vaadin-form-layout over vaadin-horizontal-layout combined with vaadin-vertical-layout?

Kind regards,

Sjoerd Brauer

Hi Sjoerd

It certainly is possible with both ways, but they both have pros and cons. Here are my two cents:

With HorizontalLayout and VerticalLayout, you have much more control to make very specific and custom form layouts, with vaying amount of items per row and other layouting options like [justify-content]
(https://vaadin.com/components/vaadin-ordered-layout/java-examples). I mostly build my form layouts myself using this approach, as I am more free to implement custom needs.

However, sometimes it is much more convenient to use a FormLayout, if the desired layout is simple enough. The FormLayout will look nice without any configurations to it, and it will definitely be easier/faster this way in such a case. I also like the option to use formLayout.addFormItem(..) which will make the label component appear to the left of the input, even though you will have to manage a separate Label component instead of using the input’s label property.

IMHO the benefit of using the FormLayout is that you can have multiple columns and also make it responsive so labels will be to the left if there is room (desktop snd tablet) and above the fields if its a small screen (mobile).