我在父级中有一个过滤器组合。我的示例图片在这里:
我想从此过滤器组合中添加一个组。我的示例代码如下:
// create parent layout
GridLayout parentLayout = new GridLayout(1, true);
parent.setLayout(parentLayout);
// design filter composite layout
Group grp = new Group(parent, SWT.NONE);
RowLayout grdLay = new RowLayout();
GridData grdData = new GridData();
grp.setLayoutData(grdData);
grp.setLayout(grdLay);
Composite grpComp = new Composite(grp,SWT.NONE);
GridData gdData = new GridData();
RowLayout grplayout = new RowLayout();
grpComp.setLayout(grplayout);
grpComp.setLayoutData(gdData);
Composite filterComposite = new Composite(grpComp, SWT.NONE);
GridData gd_filterComposite = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_filterComposite.widthHint = 1611;
gd_filterComposite.heightHint = 42;
filterComposite.setLayoutData(gd_filterComposite);
RowLayout filterCompositeLayout = new RowLayout();
filterCompositeLayout.type = SWT.VERTICAL;
filterCompositeLayout.marginHeight = 5;
filterCompositeLayout.center = true;
filterCompositeLayout.fill = true;
filterCompositeLayout.justify = true;
filterCompositeLayout.wrap = true;
filterComposite.setLayout(filterCompositeLayout);
filterCompositeLayout.spacing = 20;
但我有一个错误。我的错误图片在这里:
我怎么能做到这一点?有人可以提一些建议吗?谢谢。
答案 0 :(得分:1)
对于属于RowLayout的控件,布局数据必须是RowData。
所以
RowData gdData = new RowData();
因为grpComp
是RowLayout
grp
的一部分
类似地,filterComposite
布局数据应为RowData
。
您必须始终将控件的布局数据与包含该控件的Composite的布局相匹配。