我想在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);
}
您可能想尝试[WindowBuilder Pro](http://www.eclipse。 org/windowbuilder /) – Kai
您正在泄漏图像和字体。如果您创建图像或字体,则必须安排它在不再需要时进行处理。也不要多次创建相同的字体,这是浪费内存。 –
谢谢greg-449和user714965,我再次修复了我的字体定义,WindowBuilder Pro可能很有用,但我不想使用生成的代码。我更喜欢写我自己的代码。 – selentoptas