FormAttachment
s 用于定位 a Control
。FormAttachment
您可以使用for left、top、right 或 bottom来修复控件的边缘。自动计算所有剩余边。最简单的可能性是相对于周围复合材料边缘的百分比定位。这是一个例子:
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在这里有一本非常好的 Eclipse RCP 手册。不幸的是它是德语的。但是,您可以在第 56-57 页找到解释我上面示例的图像。