FormAttachment
s的用来定位Control
。您可以通过使用左侧,顶部,右侧或底部的FormAttachment
来修复控件的边缘。所有剩余的边自动计算。 最简单的可能性是相对于周围复合材料边缘的百分比定位。这里有一个例子:
FormData formData = new FormData();
// Fix the left edge of the control to 25% of the overall width + 10px offset.
formData.left = new FormAttachment(25, 10);
// Fix the lower edge of the control to 75% of the overall height + 0px offset.
formData.bottom = new FormAttachment(75);
// Tell the control its new position.
control.setLayoutData(formData);
Alternativelyyou可以使用构造器new FormAttachment(control, offset, alignment)
修复控制relativ的边缘到另一个控制的边缘:
FormData formData = new FormData();
// Fix left edge 10px to the right of the right edge of otherControl
formData.left = new FormAttachment(otherControl, 10, SWT.RIGHT);
// Fix bottom edge at exactly the same height as the one of otherControl
formData.bottom = new FormAttachment(otherControl, 0, SWT.BOTTOM);
control.setLayoutData(formData);
有拉尔夫一个很好的Eclipse RCP手册Ebert here。不幸的是它是用德语。但是,您可以在第56-57页上找到解释上述示例的图像。
来源
2012-08-05 16:58:01
Baz
BTW:你想读哪些值? FormAttachment的'numerator'和'offset'值或'Text'中包含的文本? – Baz 2012-08-05 15:11:23
分子和偏移 – Yrais 2012-08-05 16:54:39