zachary zachary - 1 month ago 6
Java Question

How to make GridLayout row fill availible space?

I have a

GridLayout
. I have two rows. I want one row to take up 500 pixels. I want the other row to take up the rest of the space.

How can I do this?

Answer

That's not a property of the GridLayout, but of the contained widgets' layout data. Say your composite contains two widgets:

parent.setLayout( new GridLayout() );

Button upper = new Button( parent, SWT.PUSH );
GridData upperData = new GridData( SWT.FILL, SWT.TOP, true, false );
upperData.heightHint = 500;
upper.setLayoutData( upperData );

Button lower = new Button( parent, SWT.PUSH );
GridData lowerData = new GridData( SWT.FILL, SWT.FILL, true, true );
lower.setLayoutData( lowerData );