2

如何从formAttachmentin Java 中读取值?

这是我的代码:

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);

结果:

剩下一个

4

1 回答 1

2

FormAttachments 用于定位 a ControlFormAttachment您可以使用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 页找到解释我上面示例的图像。

于 2012-08-05T16:58:01.097 回答