I don’t know if this is by design or not, but I could only get the label positioning to work by using FormLayout.addFormItem(Component, Label). For example:
FormLayout nameLayout = new FormLayout();
TextField titleField = new TextField();
TextField firstNameField = new TextField();
TextField lastNameField = new TextField();
nameLayout.addFormItem(titleField, "Title");
nameLayout.addFormItem(firstNameField, "Firstname");
nameLayout.addFormItem(lastNameField, "Lastname");
Also make sure that the responsive steps are defined correctly.
nameLayout.setResponsiveSteps(new ResponsiveStep("0", 1, LabelsPosition.TOP),
new ResponsiveStep("600px", 1, LabelsPosition.ASIDE));
Srinivasa Babu:
yes it looks by default on the TOP but if you add the items individually using addItem it puts them left & right.
That’s just silly. There should be a predictable and reliable way of adding fields to a form and choosing how the labels will appear and behave. I invite someone from Vaadin to elaborate on this and thank them in advance!
Srinivasa Babu:
yes it looks by default on the TOP but if you add the items individually using addItem it puts them left & right.
That’s just silly. There should be a predictable and reliable way of adding fields to a form and choosing how the labels will appear and behave. I invite someone from Vaadin to elaborate on this and thank them in advance!
Javac, as far as I can tell the FormLayout is both predictable and reliable. I use many FormLayouts in my app and all of them have the label exactly where I want it, which is aside when on a wider screen and top when on a smaller screen.
Srinivasa Babu:
yes it looks by default on the TOP but if you add the items individually using addItem it puts them left & right.
That’s just silly. There should be a predictable and reliable way of adding fields to a form and choosing how the labels will appear and behave. I invite someone from Vaadin to elaborate on this and thank them in advance!
Javac, as far as I can tell the FormLayout is both predictable and reliable. I use many FormLayouts in my app and all of them have the label exactly where I want it, which is aside when on a wider screen and top when on a smaller screen.
I understand what you are saying. But - why would form fields appear differently depending on whether you do for example something like this:
formLayout.add(firstName, lastName);
// OR
formLayout.addFormItem(firstName, "labelToBeUsed");
// or
formLayout.addFormItem(firstName, firstName);
formLayout.AddFormItem creates a FormItem container that separates the label and the component(s). That way, it can re-position the labels according to the responsivesteps.
When you call formLayout.add() its just adding your components and not generating a separate label.
In short, if you want to reposition the labels according to responsivesteps, you should always use FormItem.