SWT中的FormLayout[1]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

 象其它的layout类一样,FormLayout用的data类是:FormData。FormData用另外一个类来控制窗口小部件的大小和位置: FormAttachment.一个FormData最多用4个FormAttachment,它们分别对应这个小部件的4个面:顶部,底部,左边和右边。FormAttachment定义了小部件在parent composite或是这个composite里其它部件的位置。

FormAttachment计算位置和大小的方法:

y=ax+b
 

在这个等式中,在数学上y代表的是纵坐标,x是横坐标值.a是斜率,b是偏移量.按照FormAttachment的规则,y是高,x是宽度,a是一个相对其它部件的百分率,b是偏移量.FormAttachment实例中的每个数据成员分别代表这些值.

以下(表一)是FormAttachment的数据成员表和相应的意思:

表一:FormAttachment数据成员

Attribute

Description

int alignment

指定是以另外一个部件的哪一边为基准的.可能的值是:SWT.TOP, SWT.CENTER, 和 SWT.BOTTOM.默认是以最近的一边为基准.

Control control

指定FormAttachment是以哪个部件为参照物.

int denominator

指定分母.默认值为100

int numerator

指定分子

int offset

指定离composite边界或部件的边界的偏移量.单位是象素.

 

FormAttachment 拥有5个构造函数,没有一个是空的,它们如下表(表二)所示:

表二:FormAttachment的构造函数:

Constructor

Description

FormAttachment(Control control)

以另外的某个部件为参照物.

FormAttachment(Control control, int offset)

以另外的某个部件为参照物,加上偏移量.

FormAttachment(Control control, int offset, int alignment)

以另外的某个部件为参照物,加上偏移量和alignment

FormAttachment(int numerator)

设定分子.分母为100,没有偏移量

FormAttachment(int numerator, int offset)

指定分子和偏移量和100的分母

FormAttachment(int numerator, int denominator, int offset)

特定的分子,分母,偏移量

FormData最多包含4个FormAttachment实例,每个对应了与它联系的部件的一边.另外,FormData也可以指定宽和高.表四列出了FormData的数据成员:

Attribute

Description

FormAttachment bottom

The FormAttachment corresponding to the bottom side of the control.

这个FormAttachment用来指定部件的底部位置

int height

这个部件的高度.单位为象素.

FormAttachment left

这个FormAttachment用来指定部件的左部位置

FormAttachment right

这个FormAttachment用来指定部件的右部位置

FormAttachment top

这个FormAttachment用来指定部件的顶部位置

int width

这个部件的宽度.单位为象素.

本文关键:SWT中的FormLayout
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top