天天看點

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]