Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
How to expand Fields on Form?
Hi Everybody!
I have a Window containing a Form. I want the Fields to expand when I resize the Window (see screenshot). But I do not know how. Among other things I already tried to replace the default layout with a VerticalLayout. But that did not work either.
I searched the forum unsuccessfully. Any ideas?
The Window:
public class TestWindow extends Window {
private VerticalLayout contentRoot;
public TestWindow() {
setWidth(35, Sizeable.UNITS_PERCENTAGE);
contentRoot = (VerticalLayout)getContent();
TestBean tBean = new TestBean();
tBean.setName("TestBean");
BeanItem item = new BeanItem(tBean);
Form form = new Form();
contentRoot.addComponent(form);
form.setItemDataSource(item);
// form.setLayout(new VerticalLayout());
// form.setWidth(100, Sizeable.UNITS_PERCENTAGE);
}
}
Thanks for your help.
Kurt
Form by default is 100% width and the FormLayout created by Form by default is also 100% width. The problem is that the fields generated by Form are not. You have to provide a FormFieldFactory or then override the Form attachField e.g.
Form form = new Form() {
@Override
protected void attachField(Object propertyId, Field field) {
super.attachField(propertyId, field);
field.setWidth("100%");
}
};
Johannes,
thanks for your answer.
I just saw that I phrased my question in a bad way. I should not have written that I do not know how to do it, I should have written that I am searching for an "easy" way to do it without using a FieldFactory (as I know how to do it that way).
Be it as it may, your answer is exactly what I was looking for. Thank you very much for your help and your time.
Kurt
P.S.: For those of you who want to use a FieldFactory for achieving expanding Fields do something like this:
class MyFieldFactory extends FieldFactory {
@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
Field field = super.createField(item, propertyId, uiContext);
field.setWidth(100, Sizeable.UNITS_PERCENTAGE);
return field;
}
}