Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java、SWT、FormLayout—为什么我添加子项的顺序很重要?_Java_Swt_Form Layout - Fatal编程技术网

Java、SWT、FormLayout—为什么我添加子项的顺序很重要?

Java、SWT、FormLayout—为什么我添加子项的顺序很重要?,java,swt,form-layout,Java,Swt,Form Layout,我正在为复合容器使用FormLayout。 当我添加两个子项label和clientArea时,clientArea取决于label- clientArea仅在我首先添加标签时显示 在添加子对象后,在容器上调用layout()没有帮助-clientArea不会显示 如何将子级添加到FormLayout控制的容器中,而不依赖于它们之间的依赖关系 MyLabel label; Composite clientArea; public MyContainer(Composite parent,

我正在为复合容器使用FormLayout。 当我添加两个子项label和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=新格式附件(标签,-5)
此时,
标签
null
。它没有实例化。所以基本上你什么都不做。如果要将
clientrea
附加到
label
,ofc需要先实例化
label
,然后实例化
clientrea


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

formData4ClientArea.right=newformattachment(label,-5)
此时,
标签
null
。它没有实例化。所以基本上你什么都不做。如果要将
clientrea
附加到
label
,ofc需要先实例化
label
,然后实例化
clientrea


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

事实上,您实例化组件的顺序并不重要

您不能在对象创建之前引用它。正如Plygnome所述,问题在于当您创建
格式附件
时,
标签
null


在我们的项目中,我们首先创建所有组件,然后创建它们的所有布局数据对象。

事实上,实例化组件的顺序并不重要

您不能在对象创建之前引用它。正如Plygnome所述,问题在于当您创建
格式附件
时,
标签
null

在我们的项目中,我们首先创建所有组件,然后创建它们的所有布局数据对象。

许多布局(例如
GridLayout
说明了添加顺序,就好像它们是布局约束一样。许多布局(例如
GridLayout
说明了添加顺序,就好像它们是布局约束一样。