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();
                BeanItem item = new BeanItem(tBean);
                Form form = new Form();
//                form.setLayout(new VerticalLayout());
//                form.setWidth(100, Sizeable.UNITS_PERCENTAGE);

Thanks for your help.

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() {
            protected void attachField(Object propertyId, Field field) {
                super.attachField(propertyId, field);


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.


P.S.: For those of you who want to use a FieldFactory for achieving expanding Fields do something like this:

class MyFieldFactory extends FieldFactory {
        public Field createField(Item item, Object propertyId, Component uiContext) {
                Field field = super.createField(item, propertyId, uiContext);
                field.setWidth(100, Sizeable.UNITS_PERCENTAGE);
                return field;