GridLayout使用

在一个Composite放一个Label和一个Text, 其中Text自动填满剩余的水平space:

Composite permissionComposite = toolkit.createComposite(actionDetailComposite);
final GridLayout gl_permissionComposite = new GridLayout(2, false);
permissionComposite.setLayout(gl_permissionComposite);
permissionComposite.setLayoutData(new GridData  (GridData.FILL_HORIZONTAL));

Label permissionLabel = new Label(permissionComposite, SWT.NONE);
permissionLabel.setText("permission");
GridData gd_permissionLabel = new GridData(GridData.FILL_BOTH);
gd_permissionLabel.horizontalSpan = 2;  //占2格
permissionLabel.setLayoutData(gd_permissionLabel);

Label typeLabel = new Label(permissionComposite, SWT.NONE);
typeLabel.setText("type:");
Text typeText = new Text(permissionComposite, SWT.BORDER);
typeText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

如果其中父composite(actionDetailComposite)有两格new GridLayout(2,false),在某子composite来定义两格,实现上述功能,需将父composite定义如下:
GridData gb_actionDetail = new GridData(SWT.FILL, SWT.FILL, true, true);
actionDetailComposite.setLayoutData(gb_actionDetail);

你可能感兴趣的:(layout)