Java SWT:如何为每个复合材料使用多个布局?
Java SWT: How to use multiple layouts per Composite?
我有一个扩展 Composite 的 class,我想要的是有一个标题(在本例中为标签),后跟单独一行上的三个控件,如下所示:
标题
[按钮]文本[按钮]
到目前为止,我已经有了添加按钮、文本、按钮的代码,但我不知道如何在这三个顶部的标签中添加。
如何在顶部添加标题(标签),然后在底部添加三个控件?
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);
}
}
只需让标签跨越三列即可:
Label label = new Label(this, SWT.LEFT);
label.setText("title");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1));
我有一个扩展 Composite 的 class,我想要的是有一个标题(在本例中为标签),后跟单独一行上的三个控件,如下所示:
标题
[按钮]文本[按钮]
到目前为止,我已经有了添加按钮、文本、按钮的代码,但我不知道如何在这三个顶部的标签中添加。
如何在顶部添加标题(标签),然后在底部添加三个控件?
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);
}
}
只需让标签跨越三列即可:
Label label = new Label(this, SWT.LEFT);
label.setText("title");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1));