How to set a caption for a Checkbox in a FormLayout in Vaadin Flow

Viewed 161

In FormLayout all my components have a caption label just above the component except for the Checkbox. So for example if I have a row with just a single Checkbox (the other column is empty or the Checkbox question spans two columns) then it's very disproportionally close to the row above. Is there a way to add a caption like the other components? In my case the Checkbox is a question whereas the caption is just a simple title of what the Checkbox represents.

1 Answers
// configure to your liking responsively
formLayout.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 2, FormLayout.ResponsiveStep.LabelsPosition.TOP));

formLayout.addFormItem(new Checkbox(), "Any label you want aligned with other labels");
Related