Ski*_*kip 1 java swt form-layout
我正在使用FormLayout作为Composite容器.当我添加两个孩子标签和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);
Run Code Online (Sandbox Code Playgroud)
formData4ClientArea.right = new FormAttachment(label,-5);在这一点上,label是null.它没有实例化.所以基本上你将clientArea附加到任何东西.如果你想要clientArea附加label,ofc你需要首先实例化label,然后clientArea
但是,另一方面,为什么订单对你很重要?
| 归档时间: |
|
| 查看次数: |
245 次 |
| 最近记录: |