Eclipse大本营


SWT开发 - Label的使用(2)

2008-01-22 00:32Update

eclipse

本文介绍使用SWT开发一个简单的窗口程序,该窗口程序采用FillLayout排版方法来显示2个Label(线条风格)

代码:LabelSample02.java
package com.test.swt;

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

public class LabelSample02 {
    public static void main (String[] args) {
        Display display = new Display ();
        Shell shell = new Shell (display);
        shell.setLayout (new FillLayout ());
        new Label (shell, SWT.SEPARATOR | SWT.HORIZONTAL);
        new Label (shell, SWT.SEPARATOR | SWT.VERTICAL);
        shell.setSize (200, 200);
        shell.open ();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        display.dispose ();
    }
}


FillLayout
FillLayout按照子控件被添加的顺序对子控件进行布局,FillLayout多用来放置一个子控件填满父窗口。我们以后用专门的文章来介绍它。

下面的语句创建一个水平(HORIZONTAL)的分割条(SEPARATOR)
new Label (shell, SWT.SEPARATOR | SWT.HORIZONTAL);

而下面的语句创建一个垂直(VERTICAL)的分割条(SEPARATOR)
new Label (shell, SWT.SEPARATOR | SWT.VERTICAL);

编译,执行后显示
 
Copyright ©2006-2010 lifevv.com. All Rights Reserved
POWERED BY @pmplat.syboos.com