記錄這些筆記的主要目的是想提高自已的寫作水平和英文能力.原來讀書不努力,希望現在還來得及.
這些東西是Apress.The.Definitive.Guide.to.SWT.and.JFace.2004.LiB.chm中的簡化版本.
如有錯誤請多指點. :)

FillLayout是一種簡單的布局類,它放置全部的控件在一單行或單列上并保持所有控件擁有相同的大小空間.

FillLayout構造函數

構造函數 描述
public FillLayout() 默認使用布局類型為 SWT.HORIZONTAL
public FillLayout(int type) 指定布局類型為 type


type的值為 SWT.HORIZONTAL,控件將放置在單行上. SWT.VERTICAL則將控件放置在單列上.
注意: 在帶參數FillLayout(int type)中, 參數值為int類型,如果你輸入的值為非上面兩種類型值,則默認使用SWT.VERTICAL.
 

讓我們來看一個實例,新建一個SWT程序,先設置Shell的布局為SWT.HORIZONTAL,然后添加三個ButtonShell上,運行程序可以看到Button的布局方式為水平方式排列.見下圖:
r_HORIZONTAL.JPG

然后將程序中的FillLayout的構造函數改為任一數值,和SWT.HORIZONTAL,SWT.VERTICAL不同.運行程序,可以看到使用了非指定的兩個數值時,SWT程序默認使用SWT.VERTICAL布局程序.見下圖:
o_any.JPG

程序清單:

package chapter4;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * @author HexUzHoNG Created on 2005-6-20
 *
 
*/

public class FillLayoutDemo {
    
    
public static void main(String[] args) {
        Display display 
= new Display();
        Shell shell 
= new Shell(display);
        shell.setSize(
300200);
        shell.setLayout(
new FillLayout(SWT.HORIZONTAL));
        
new Button(shell, SWT.PUSH).setText("one");
        
new Button(shell, SWT.PUSH).setText("two");
        
new Button(shell, SWT.PUSH).setText("three");
        shell.open();
        
while (!shell.isDisposed()) {
            
if (!display.readAndDispatch()) {
                display.sleep();
            }

        }

        display.dispose();
    }

    
}