List<FormLayout.ResponsiveStep> responsiveStep = List.of(new FormLayout.ResponsiveStep("0", 1, FormLayout.ResponsiveStep.LabelsPosition.TOP), // 1 column for small screens (top labels)
new FormLayout.ResponsiveStep("600px", 2, FormLayout.ResponsiveStep.LabelsPosition.ASIDE));
basicItemInfoLayout.setResponsiveSteps(responsiveStep);
This fixed the issue. Also looks like the order is important here. Small screen width should go first and then the next size. If we put the bigger size first in the array, it doesn’t work as expected.
I have exactly the opposite problem. I want a 2-column layout with the labels before the field.
Unfortunately, the label always ends up above the field for me.
TextField title = new TextField("Titel");
DatePicker startDate = new DatePicker("Aktionstart");
TextField startWeek = new TextField("KW");
formLayout.setAutoResponsive(true);
formLayout.setExpandColumns(true);
formLayout.setExpandFields(true);
formLayout.setLabelsAside(true);
formLayout.setResponsiveSteps(new ResponsiveStep("0", 1, ResponsiveStep.LabelsPosition.ASIDE), new ResponsiveStep("800px", 2, ResponsiveStep.LabelsPosition.ASIDE));
formLayout.addFormRow(new H3("Kampagne"));
title.setReadOnly(true);
binder.forField(title).bind(CampaignUITO::getTitle, CampaignUITO::setTitle);
formLayout.addFormRow(title);
startDate.setRequired(true);
startDate.addValueChangeListener(event -> {
// .. get week of startdate
});
startWeek.setReadOnly(true);
formLayout.addFormRow(startDate, startWeek);
Do you have any idea what the problem might be here? I only have Vaadin 24.9.12.
Sadly yes, the formlayout does not support labels on fields if the formlayout is the one who does the label positioning… meaning instead of adding “KW” to the field, it has to be done as second parameter via addFormRow(field, label)
Thank you both. Then I’ll turn 2 columns into 4 ;-). @knoobie Yes, unfortunately, the environments leave little room for Vaadin, but I’ll do my best to change that.