我正在为复合容器使用 FormLayout。当我添加两个子标签和clientArea时,其中 clientArea 取决于标签 - 只有在我首先添加标签时才会出现 clientArea。
在容器上调用 layout() 后,添加子项无济于事 - clientArea 不显示。
如何将子级添加到 FormLayout 控制的容器中,独立于它们彼此的依赖关系?
MyLabel label;
Composite clientArea;
public MyContainer(Composite parent, int style) {
super(parent,style);
//choose the container Layout
FormLayout layout = new FormLayout();
this.setLayout(layout);
clientArea = new Composite(this, SWT.NONE);
FormData formData4ClientArea = new FormData();
formData4ClientArea.left = new FormAttachment(0,0);
formData4ClientArea.top = new FormAttachment(0,5);
formData4ClientArea.right = new FormAttachment(label,-5);
formData4ClientArea.bottom = new FormAttachment(100,-5);
//set the Formdata
clientArea.setLayoutData(formData4ClientArea);
clientArea.setBackground(getDisplay().getSystemColor(SWT.COLOR_GREEN));
//create the label
label = new MyLabel(this, SWT.NONE);
FormData formData4Label = new FormData();
formData4Label.top = new FormAttachment(0,5);
formData4Label.right = new FormAttachment(100,-5);
formData4Label.bottom = new FormAttachment(100,-5);
//set the FormData
label.setLayoutData(formData4Label);