GridLayout columns

Hello,

I’d like to fix the width of the columns of my GridLayout. There are 2 columns and I want each column to take up 50% of the availlable space.

I use the following method :

grid.setColumnExpandRatio(0, 0.5f);
grid.setColumnExpandRatio(1, 0.5f);

but it doesn’t work.

Any suggestion ?

Thanks,
Kevin.

Would it be possible to set the components in the columns as 100% wide? That is one way to fix it.

Actually, I have textfields and I can’t make them take up 100% wide.
11302.png

Hi,

It’s hard to say exactly how you should do it, without knowing exactly what you have.

Here is one example - a GridLayout with two forms and a TextField outside the forms, set to 100% in the way Risto suggested. The “inner textfields” are not 100% or expanded in any way.

GridLayout gl = new GridLayout(2, 2);
        gl.setWidth("100%");
        mainWindow.addComponent(gl);

        Form form1 = new Form();
        form1.setItemDataSource(new BeanItem(new MyBean()));
        form1.setWidth("100%");
        gl.addComponent(form1);

        Form form2 = new Form();
        form2.setItemDataSource(new BeanItem(new MyBean()));
        form2.setWidth("100%");
        gl.addComponent(form2);

        TextField tf = new TextField();
        tf.setWidth("100%");
        tf.setHeight("40px");

        gl.addComponent(tf);

But this might not be what you are after?

Best Regards,
Marc

Actually, it works if I put my textfields into HorizontalLayout 100% wide.