[英]Java SWT: How to use multiple layouts per Composite?
我有一個擴展Composite的類,我想要的是一個標題(在這種情況下為標簽),然后在一個單獨的行上包含三個控件,如下所示:
標題
[按鈕] TEXT [按鈕]
到目前為止,我已經在Button,text,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);
}
}
只需使標簽跨越三列即可:
Label label = new Label(this, SWT.LEFT);
label.setText("title");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.