簡體   English   中英

如何在 SWT 中設計組合

[英]How to design a Composite in SWT

我想在 A 側的復合中放置 3 個固定大小的組。 我想把圖像和標簽放在這個組的中間。 我的示例圖像和代碼如下。 問題是根據其中的標簽大小調整組的大小,並且標簽寫在組的頂部,但我希望將位置組設為相等的固定大小以覆蓋 A 邊的寬度,並且標簽應位於組的垂直中間。

private void designComposite() {

    Section sectionA = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
    sectionA.setText("A");

    Composite sectionClientA = toolkit.createComposite(sectionA);
    sectionClientA.setLayout(new RowLayout());

    Composite dynamicDataComp = toolkit.createComposite(sectionClientA);

    dynamicDataComp.setLayout(new RowLayout());

    Group group_incom = new Group(dynamicDataComp, SWT.NONE);
    group_incom.setLayout(new RowLayout());
    Label lbl_img_incom = new Label(group_incom, SWT.CENTER);
    Image img_incom = new Image(lbl_img_incom.getDisplay(),
            "<path>");
    lbl_img_incom.setImage(img_incom);
    group_incom.setText("# of Incoming Messages :");
    Label lbl_incomMsg = toolkit.createLabel(group_incom, "99", SWT.CENTER | SWT.VERTICAL);
    Font incomFont = new Font(lbl_incomMsg.getDisplay(), new FontData("Arial", 12, SWT.BOLD));
    lbl_incomMsg.setFont(incomFont);
    lbl_incomMsg.pack();

    Group group_outgo = new Group(dynamicDataComp, SWT.NONE);
    group_outgo.setLayout(new RowLayout());
    Label lbl_img_outgo = new Label(group_outgo, SWT.CENTER);
    Image img_outgo = new Image(lbl_img_outgo.getDisplay(),
            "<path>");
    lbl_img_outgo.setImage(img_outgo);
    group_outgo.setText("# of Outgoing Messages :");
    Label lbl_outgoMsg = toolkit.createLabel(group_outgo, "145639612", SWT.CENTER);
    Font outgoFont = new Font(lbl_outgoMsg.getDisplay(), new FontData("Arial", 13, SWT.BOLD));
    lbl_outgoMsg.setFont(outgoFont);
    lbl_outgoMsg.pack();

    Group group_error = new Group(dynamicDataComp, SWT.NONE);
    group_error.setLayout(new RowLayout());
    Label lbl_img_error = new Label(group_error, SWT.CENTER);
    Image img_error = new Image(lbl_img_error.getDisplay(),
            "<path>");
    lbl_img_error.setImage(img_error);
    group_error.setText("# of Error Messages :");
    Label lbl_errorMsg = toolkit.createLabel(group_error, "345", SWT.CENTER);
    Font errorFont = new Font(lbl_errorMsg.getDisplay(), new FontData("Arial", 13, SWT.BOLD));
    lbl_errorMsg.setFont(errorFont);
    lbl_errorMsg.pack();

    sectionA.setClient(sectionClientA);

}

在此處輸入圖片說明

一種方法是對父組合使用GridLayout並告訴它使用 3 個相同大小的列:

Composite dynamicDataComp = toolkit.createComposite(sectionClientA);

dynamicDataComp.setLayout(new GridLayout(3, true));

使用GridLayout並將列設置為等寬:

Composite dynamicDataComp = new Composite(parent, SWT.NONE);
    dynamicDataComp.setLayout(new GridLayout(3, true));
    dynamicDataComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

Group group_incom = new Group(dynamicDataComp, SWT.NONE);
        group_incom.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        group_incom.setLayout(new RowLayout());

//...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM