Reputation: 30097
How to make some columns of GridLayout
grow in SWT
?
I put 3 controls into grid layout and found they are not grow with window, despite the fact I set FILL
style.
The code:
public class GridLayout01 {
public static void main(String[] args) {
GridLayout gridLayout;
Display display = new Display();
Shell shell = new Shell(display);
gridLayout = new GridLayout(3, false);
shell.setLayout(gridLayout);
{
Label promptLabel = new Label(shell, SWT.NONE);
promptLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
promptLabel.setText("PROMPT:");
Text commandLineText = new Text(shell, SWT.SINGLE);
commandLineText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Button commandLineButton = new Button( shell, SWT.PUSH);
commandLineButton.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
commandLineButton.setText("Say");
}
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
Upvotes: 0
Views: 609
Reputation: 36884
Depending on whether you want it to grow vertically or horizontally, you need to set the GridData
as follows:
Horizontal fill: new GridData(SWT.FILL, ?, true, ?)
Vertical fill: new GridData(?, SWT.FILL, ?, true)
Here is the Javadoc:
GridData(int horizontalAlignment,
int verticalAlignment,
boolean grabExcessHorizontalSpace,
boolean grabExcessVerticalSpace)
horizontalAlignment
- how control will be positioned horizontally within a cell, one of: SWT.BEGINNING
(or SWT.LEFT
), SWT.CENTER
, SWT.END
(or SWT.RIGHT
), or SWT.FILL
verticalAlignment
- how control will be positioned vertically within a cell, one of: SWT.BEGINNING
(or SWT.TOP
), SWT.CENTER
, SWT.END
(or SWT.BOTTOM
), or SWT.FILL
grabExcessHorizontalSpace
- whether cell will be made wide enough to fit the remaining horizontal spacegrabExcessVerticalSpace
- whether cell will be made high enough to fit the remaining vertical spaceAlso make sure that the parent takes up all the space you want the children to occupy.
Upvotes: 2