如何从Java中的formAttachment
读取值?
这是我的代码:
Text one = new Text(composite, SWT.BORDER);
data = new FormData();
data.top = new FormAttachment(0, 0);
data.bottom = new FormAttachment(100, 0);
data.left = new FormAttachment(0, 0);
data.right = new FormAttachment(sash, 0);
one.setLayoutData(data);
结果:
最佳答案
FormAttachment
用于定位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);
或者,您可以使用构造器
new FormAttachment(control, offset, alignment)
将相对控件的边缘固定到另一个控件的边缘: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);
Ralf Ebert here有一本非常好的Eclipse RCP手册。不幸的是它是德语。但是,您可以在第56-57页上找到解释我的示例的图像。