Aligning save button in a Form

hello,
i have a form like in the attached picture.
i want to align the save button and error message to the form fields (text fields)
i want save buttons, error messages and form fields start position should be on the same vertical line.
is this possible without dealing with css?
if not, how i can guaranty save button and error message text will be aligned vertically with form fields (i don’t want them to effect form fields label changes, because my application will be multilingual).
thanks in advance for your answers.
11740.png

If I understood your problem correctly just put all your components within a FormLayout. Then the captions will be shown on the left (taking as much space as the longest caption) and the contents will all be aligned.

hi Anna,
you’re right, if i put components in a form layout, it is rendered how i want.
but this time i cannot use a pojo as datasource and i must add fields manually to the form layout.
any other ideas?

You could yry using a GridLayout:

GridLayout grid = new GridLayout();
grid.setColumns(2);

grid.addComponent(label1);
grid.addComponent(textField1);

grid.addComponent(label2);
grid.addComponent(textField2);

grid.setRows(layout.getRows() + 1);
grid.addComponent(pleaseEnterBlahBlahLabel, grid.getCursorX(), grid.getCursorY(), grid.getCursorX() + 1, grid.getCursorY());

grid.space();
grid.addComponent(saveButton);


You can use a FormLayout without a form, and Royce’s suggestion with the GridLayout works as well.

In the GridLayout example I’d just prefer defining the size in the constructor and putting all components in their right place directly, instead of playing around with setRows and getXpos etc…

GridLayout grid = new GridLayout(2, 4);

grid.addComponent(label1, 0, 0);
grid.addComponent(textField1, 1, 0);

grid.addComponent(label2, 0, 1);
grid.addComponent(textField2, 1, 1);

grid.addComponent(pleaseEnterBlahBlahLabel, 0, 2, 1, 2);
grid.addComponent(saveButton, 1, 3);

Thanks Royce and Jens.
Probably i will use a FormLayout (it works well for my aligning needs)
I just wanted to use a Form instead of a FormLayout to avoid adding form fields manually (in Form i use a FormFieldFactory class to generate the form fields and just set the Form’s field factory)
Thanks anyway.