论坛首页 Java企业应用论坛

GridLayout使用

浏览 5269 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-05-22   最后修改:2009-05-22
在一个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);
   发表时间:2009-05-22  
rainShare 写道
在一个Composite放一个Label和一个Text, 其中Text自动填满剩余的水平space:

Composite permissionComposite = toolkit.createComposite(actionDetailComposite);
final GridLayout gl_permissionComposite = new GridLayout(2, false);
permissionComposite.setLayout(gl_permissionComposite);
[color=red][b]permissionComposite.setLayoutData(new GridData  (GridData.FILL_HORIZONTAL));[/b][/color]

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);
[color=red]typeText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));[/color]


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

0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics