在运行程序时,要设置运行时参数,在http://www.eclipse.org上有这些关于SWT的FAQ,请自行参考。

解决方案 »

  1.   

    examples要通过Update里面去下载!
      

  2.   

    examples 我已经下载 解压了
    怎么用
    没人说说么?
      

  3.   

    将eclipse\plugins\org.eclipse.swt.win32_2.x.x\os\win32\x86下的文件Copy到\Windows将eclipse\plugins\org.eclipse.swt.win32_2.x.x\ws\win32下的jar加入classpath。
    x是你的eclipse版本。
      

  4.   

    在IBM dW的站点上:可以找到非常有用的三篇文章.
    使用SWT开发的Java GUI真的是非常高效和界面亲切(在Win32上与VC,VB开发的应用或Unix上的Motif极其相似),既考虑了友好界面又考虑了Java的平台无关,很爽的开发库...
    http://www-106.ibm.com/developerworks/opensource/library/os-ecgui1/
    http://www-106.ibm.com/developerworks/opensource/library/os-ecgui2/
    http://www-106.ibm.com/developerworks/opensource/library/os-ecgui3/
      

  5.   

    为什么他的例子编译的时候出错
    shell.setLayout(gShellLay);--------->
    The method setLayout(Layout) in the type Composite is not applicable for the arguments (GridLayout)
    shell.addDisposeListener(new DisposeListener(){
    --------------->DisposeListener cannot be resolved or is not a type/*
     * Created on 2003-4-16
     *
     * To change the template for this generated file go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     *//**
     * @author 
     *
     * To change the template for this generated type comment go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     */
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.layout.GridData;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.widgets.Text;
    import org.eclipse.swt.events.MouseAdapter;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.internal.SWTEventListener;
    import org.eclipse.swt.internal.*;
    import java.util.*;
    import java.util.EventListener;
    import java.awt.*;
    import java.awt.GridLayout;public class OpenShell{
    public static void main(String [] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.open();
        // 开始事件处理循环,直到用户关闭窗口
    while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
     private void initShell(Shell shell) {
            //为Shell设置布局对象
            GridLayout gShellLay = new GridLayout();
            shell.setLayout(gShellLay);
            //构造一个Composite构件作为文本框和按键的容器
            Composite panel = new Composite(shell,SWT.NONE);
            //为Panel指定一个布局结构对象。这里让Panel尽可能的占满Shell,也就是全部应用程序窗口的空间。
            GridData gPanelData = new GridData(GridData.GRAB_HORIZONTAL|GridData.GRAB_VERTICAL|GridData.FILL_BOTH);
            panel.setLayoutData(gPanelData);
            //为Panel也设置一个布局对象。文本框和按键将按这个布局对象来显示。
            GridLayout gPanelLay = new GridLayout();
            panel.setLayout(gPanelLay);
            //为Panel生成一个背景色
            final Color bkColor = new Color(Display.getCurrent(),200,0,200);
            panel.setBackground(bkColor);
            //生成文本框
            final Text text = new Text(panel,SWT.MULTI|SWT.WRAP);
            //为文本框指定一个布局结构对象,这里让文本框尽可能的占满Panel的空间。
            GridData gTextData = new GridData(GridData.GRAB_HORIZONTAL|GridData.GRAB_VERTICAL|GridData.FILL_BOTH);
            text.setLayoutData(gTextData);
            //生成按键
            Button butt = new Button(panel,SWT.PUSH);
            butt.setText("Push");
            //为按键指定鼠标事件
            butt.addMouseListener(new MouseAdapter(){
                public void mouseDown(MouseEvent e){
                    //当用户点击按键的时候,显示信息
                    text.setText("Hello SWT");
                }
            });
            //当主窗口关闭时,会触发DisposeListener。这里用来释放Panel的背景色。
            shell.addDisposeListener(new DisposeListener(){
                public void widgetDisposed(DisposeEvent e) {
                    bkColor.dispose();
                }
            });
        }}