我有一个扩展Composite的类,我想要的是一个标题(在这种情况下为标签),然后在一个单独的行上放置三个控件,如下所示:
标题
[按钮]文本[按钮]
到目前为止,我已经在Button,文本,button中添加了代码,但是我不知道如何在这三个标签的顶部添加标签。
如何在顶部添加标题(标签),然后在底部添加三个控件?
public class PageControl extends Composite {
private Button nextPage;
private Button previousPage;
private Text text;
private Label label;
public PageControl(Composite parent, int style) {
super(parent, style);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.makeColumnsEqualWidth = false;
previousPage = new Button(this, style);
previousPage.setText("Previous");
previousPage.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
text = new Text(this, SWT.SINGLE | SWT.BORDER);
GridData gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
GC gc = new GC(text);
gridData.minimumWidth = gc.textExtent("123456890", 0).x;
text.setTextLimit(10);
text.setLayoutData(gridData);
nextPage = new Button(this, style);
nextPage.setText("Next");
nextPage.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
Display display = Display.getCurrent();
Color white = display.getSystemColor(SWT.COLOR_WHITE);
this.setBackground(white);
setLayout(gridLayout);
}
}
答案 0 :(得分:0)
只需使标签跨越三列即可:
Label label = new Label(this, SWT.LEFT);
label.setText("title");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1));