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