Is there an easy way to set the style for a Label to use the same style as the FormLayout in Vaadin 14 and higher?

287 Views Asked by At

Specifically if I have:

FormLayout formLayout = new FormLayout();
formLayout.add(new TextField("Label goes here"));

And instead of a FormLayout I want to use a VerticalLayout but have the same style of Labels for the fields.

VerticalLayout verticalLayout = new VerticalLayout();
Label label = new Label("Label goes here");
verticalLayout.add(label);
// setLabelStyleSameAsLabelForTextFieldInFormLayout();

In other words what code would replace the method setLabelStyleSameAsLabelForTextFieldInFormLayout()?

Important -> I'm trying to do it in such a way that doesn't involve creating CSS so that it's more future proof. That is to say if the Label in the FormLayout is updated then so is the label in the VerticalLayout.

1

There are 1 best solutions below

4
Tatu Lund On

but have the same style of Labels for the fields.

I have difficulties to understand the question. But this should be trivial by using setLabel or label set by constructor of the TextField.. So the following should produce the label which looks the same.

FormLayout formLayout = new FormLayout();
formLayout.add(new TextField("Label goes here"));

VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.add(new TextField("Label goes here"));