我正在为复合容器使用FormLayout。
当我添加两个子标签和clientArea时,clientArea取决于label-
仅当我首先添加标签时,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);

最佳答案

formData4ClientArea.right = new FormAttachment(label,-5);此时,labelnull。它没有被实例化。因此,基本上,您将clientArea附加为空。如果要将clientArea附加到label,ofc必须首先实例化label,然后再实例化clientArea

但是,另一方面,订单为什么对您很重要?

关于java - Java,SWT,FormLayout-为什么添加子项的顺序很重要?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12049890/

10-14 09:47