通过如下方式:

  /************************ 实现定时器 ***********************************/
  
  final int time=1000;
  Runnable showTime = new Runnable(){
                public void run(){
                 System.out.println("swt定时器的实现!");
                  display.timerExec(time, this);
                }
              };
         
  display.timerExec(time,showTime);//你的swt程序的display
  
  /****************************************************************/

 

完整示例如下

 

 
  
  1. package test.ftp00;  
  2.  
  3. import org.eclipse.swt.graphics.Rectangle;  
  4. import org.eclipse.swt.layout.FillLayout;  
  5. import org.eclipse.swt.layout.GridData;  
  6. import org.eclipse.swt.layout.GridLayout;  
  7. import org.eclipse.swt.widgets.Composite;  
  8. import org.eclipse.swt.widgets.Display;  
  9. import org.eclipse.swt.widgets.Monitor;  
  10. import org.eclipse.swt.widgets.Shell;  
  11.  
  12. public class TimerWindow {  
  13.     Display display;  
  14.     Shell shell;  
  15.     GridLayout gridLayout;  
  16.     GridData layoutData;  
  17.     Composite composite;  
  18.     static String xmlDir[];  
  19.  
  20.     public TimerWindow() {  
  21.         display = Display.getDefault();  
  22.         // shell = new Shell(display, SWT.NO_TRIM );  
  23.         shell = new Shell(display);  
  24.         // 初始化shell  
  25.         initShell();  
  26.  
  27.         /************************ 实现定时器 ***********************************/  
  28.  
  29.         final int time = 1000;  
  30.         Runnable showTime = new Runnable() {  
  31.             public void run() {  
  32.                 System.out.println("swt定时器的实现!");  
  33.                 display.timerExec(time, this);  
  34.             }  
  35.         };  
  36.  
  37.         display.timerExec(time, showTime);// 你的swt程序的display  
  38.  
  39.         /****************************************************************/  
  40.  
  41.         shell.open();  
  42.         while (!shell.isDisposed()) {  
  43.             if (!display.readAndDispatch())  
  44.                 display.sleep();  
  45.         }  
  46.     }  
  47.  
  48.     /**  
  49.      * 设置窗口的标题、位置、大小、图标  
  50.      *   
  51.      * @return Shell  
  52.      */  
  53.     public Shell initShell() {  
  54.         shell.setText("添加内容");  
  55.         shell.setSize(160, 500);  
  56.  
  57.         Monitor monitor = shell.getMonitor();  
  58.         Rectangle bounds = monitor.getBounds();  
  59.         Rectangle rect = shell.getBounds();  
  60.         shell.setLocation(bounds.width - 200 - rect.width, bounds.y);  
  61.         shell.setLayout(new FillLayout());  
  62.         return shell;  
  63.     }  
  64.  
  65.     public static void main(String[] args) {  
  66.         new TimerWindow();  
  67.     }