SWT - 不使用GridLayout

时间:2017-06-29 18:13:16

标签: java swt frontend

我在桌面应用程序上使用SWT,我使用的GridLayout分为5列和1行,有一个tabble使用空格的顶部,而底部我有3个按钮,我想要将这3个按钮放在右边。基本上跳了两个第一个空格。我尝试使用:

 GridData gridData = new GridData();
 gridData.grabExcessHorizontalSpace = true;
 gridData.horizontalAlignment= GridData.END;
 CompanyGroup.setLayoutData(gridData);

但我意识到这种方法只在列内对齐。

Composite rightComp = DialogCompositeFactory.create(parent);
rightComp.setLayout(new GridLayout(1, false));
Group CompanyGroup = DialogGroupFactory.create(rightComp,Message));
CompanyGroup.setLayout(new GridLayout(5, true));

如下例所示

Example

2 个答案:

答案 0 :(得分:0)

只需将空标签控件放在前两列。

// Empty first column
new Label(CompanyGroup, SWT.LEAD);

// Empty second column
new Label(CompanyGroup, SWT.LEAD);

... your buttons in the last three columns

答案 1 :(得分:0)

我假设您有按钮的合成,如果没有为按钮创建合成并设置GridData HORIZONTAL_ALIGN_END

Composite buttonsComposite = new Composite( groupComp, SWT.NONE );
GridData gd = new GridData( GridData.HORIZONTAL_ALIGN_END );
GridLayout lo = new GridLayout(3,true);
buttonsComp.setLayoutData( gd );
buttonsComp.setLayout(lo);