Chinaunix

标题: Access the SWT widget in other Thread [打印本页]

作者: wangsong2    时间: 2006-05-25 09:08
标题: Access the SWT widget in other Thread
   SWT widget is not accessible out of the SWT main thread. we must play some trick here.
  example:
class LocationControl extends Thread {
        private CustomLocation location;
        public void setLocation(CustomLocation location) {
            this.location=location;
        }
        
        public void run() {
            while ( true ) {
                location.x=location.x+2;
                try {
                    sleep(100);
                } catch ( Exception e ) {}
                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        shell.redraw();
                    }
                });
            }
            
        }
    }
   and in the main Thread , we can just start the Thread, the shell
should be redrawed every 100 ms.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4241/showart_117746.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2