【发布时间】:2012-08-21 07:08:47
【问题描述】:
我正在为复合容器使用 FormLayout。 当我添加两个孩子 label 和 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);
【问题讨论】:
-
许多布局,(例如
GridLayout考虑添加顺序,就好像它们是布局约束一样。
标签: java swt form-layout