天天看点

SWT之结合FillLayout和FormLayout结合做一个Group应用

FillLayout是布局类中最简单的,它把所有的控件放在一行或一列,并使它们有相同的大小。它有一个公有(public)的属性和类型,决定控件是放在一行还是放在一列。可以把类型传递给构造函数,也可以在构造函数后设置类型。

构造函数:

1、public FillLayout() Constructs a FillLayout and sets type to SWT.HORIZONTAL.

2、public FillLayout(int type) Constructs a FillLayout and sets type to the passed type.

FillLayout不检查type的合法性,所以可以传递任意的int值。尽管FillLayout的默认设置是SWT.HORIZONTAL,但如果传递一个既非SWT.HORIZONTAL又非SWT.VERTICAL的值,它将使用SWT.VERTICAL。

布局类FormLayout是一个依据附件的来设置控制每个控件的位置,对应与每一个FormData都有4个设置,bottom、left、right、top设置控件的位置,如:pingpongData.bottom = new FormAttachment(basketball,0,SWT.BOTTOM); FormAttachment的构造函数有多个:

Attribute

int alignment

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

Control control

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

int denominator

指定分母.默认值为100

int numerator

指定分子

int offset

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

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)

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

下面结合FillLayout和FormLayout结合做一个Group应用,并且给篮球选择框设置了一个监听器。

[img]http://dl.iteye.com/upload/attachment/0067/5554/bb79bf24-9b19-30ae-94ad-bb9e7f220c9a.png[/img]