2015-09-04 33 views
0

我想在A面中的複合材料中放置3個固定尺寸的組。我想放置這個組的圖像和標籤中間。我的示例圖像和代碼如下。問題在於組的大小是根據標籤大小調整的,標籤寫在組的頂部,但我希望地方組的大小相同,以覆蓋A邊的寬度,標籤應該垂直居中。如何在SWT中設計複合材料

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(), 
      "D:\\projects\\ATMGW_SW\\Code\\atmgw-client\\icons\\in_arrow.png"); 
    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(), 
      "D:\\projects\\ATMGW_SW\\Code\\atmgw-client\\icons\\out_arrow.png"); 
    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(), 
      "D:\\projects\\ATMGW_SW\\Code\\atmgw-client\\icons\\error.png"); 
    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); 

} 

enter image description here

+0

您可能想嘗試[WindowBuilder Pro](http://www.eclipse。 org/windowbuilder /) – Kai

+0

您正在泄漏圖像和字體。如果您創建圖像或字體,則必須安排它在不再需要時進行處理。也不要多次創建相同的字體,這是浪費內存。 –

+0

謝謝greg-449和user714965,我再次修復了我的字體定義,WindowBuilder Pro可能很有用,但我不想使用生成的代碼。我更喜歡寫我自己的代碼。 – selentoptas

回答

0

使用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()); 

//... 
0

的一種方法是使用GridLayout父複合,並告訴它使用3個相等大小的列:

Composite dynamicDataComp = toolkit.createComposite(sectionClientA); 

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

我做到了,但不起作用。我希望每個小組的大小相同,並且會覆蓋A方的寬度。雖然我創建了GridLayout,但顯示沒有改變。 – selentoptas