DANCE WITH JAVA

          開發出高質量的系統

          導航

          <2007年8月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          隨筆分類(277)

          隨筆檔案(238)

          閱讀排行榜

          常用鏈接

          統計

          積分與排名

          好友之家

          最新評論

          Swt/Jface進度條

          處理長時間的任務的時候常需要進度條顯示,有幾種實現方式
          1,普通的進度條
          import java.lang.reflect.InvocationTargetException;

          import org.eclipse.core.runtime.IProgressMonitor;
          import org.eclipse.jface.dialogs.ProgressMonitorDialog;
          import org.eclipse.jface.operation.IRunnableWithProgress;
          import org.eclipse.swt.widgets.Display;
          import org.eclipse.swt.widgets.Shell;


          public class TestProgress {
              
          static boolean stopflg = false;
              
          /**
               * Launch the application
               * 
          @param args
               
          */

              
          public static void main(String[] args) throws Exception{
                  
          final Display display = Display.getDefault();
                  
          final Shell shell = new Shell();
                  shell.setSize(
          500375);
                  shell.setText(
          "SWT Application");
                  
                  
          //
                  IRunnableWithProgress runnable = new IRunnableWithProgress(){
                      
          public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                          monitor.beginTask(
          "generate"30);
                          
          for(int i=0;i<100;i++){
                              
          if(monitor.isCanceled()){
                                  
          return;
                              }

                              monitor.worked(
          1);
                              Thread.sleep(
          50);
                          }

                          
                          monitor.done();
                      }

                  }
          ;
                  
          new ProgressMonitorDialog(shell).run(truetrue, runnable);
                  shell.open();
                  shell.layout();
                  
          while (!shell.isDisposed()) {
                      
          if (!display.readAndDispatch())
                          display.sleep();
                  }

              }


          }

          2,反復循環的進度條
          import java.lang.reflect.InvocationTargetException;

          import org.eclipse.core.runtime.IProgressMonitor;
          import org.eclipse.jface.dialogs.ProgressMonitorDialog;
          import org.eclipse.jface.operation.IRunnableWithProgress;
          import org.eclipse.swt.widgets.Display;
          import org.eclipse.swt.widgets.Shell;


          public class TestProgress {
              
          static boolean stopflg = false;
              
          /**
               * Launch the application
               * 
          @param args
               
          */

              
          public static void main(String[] args) throws Exception{
                  
          final Display display = Display.getDefault();
                  
          final Shell shell = new Shell();
                  shell.setSize(
          500375);
                  shell.setText(
          "SWT Application");
                  
                  
          //
                  IRunnableWithProgress runnable = new IRunnableWithProgress(){
                      
          public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                          monitor.beginTask(
          "generate"30);
                          
          int i=0;
                          
          while(true){
                              
          if(stopflg){
                                  
          break;
                              }

                              i
          ++;
                              
          if(i==30){
                                  i
          =0;
                                  monitor.beginTask(
          "generate"30);
                              }

                              monitor.worked(
          1);
                              Thread.sleep(
          100);
                          }

                          monitor.done();
                      }

                  }
          ;
                  
          new ProgressMonitorDialog(shell).run(truetrue, runnable);
                  shell.open();
                  shell.layout();
                  
          while (!shell.isDisposed()) {
                      
          if (!display.readAndDispatch())
                          display.sleep();
                  }

              }


          }

          3,rcp中后臺任務的進度條
          使用Job建立后臺任務,只需要設置job.setUser(true)進度條就出現了,和上邊一樣,進度條需要自己來控制進度。如果做一個cool的進度條,就看你如何讓進度條顯示出實際的任務進程。

          posted on 2007-08-10 09:59 dreamstone 閱讀(5032) 評論(0)  編輯  收藏 所屬分類: SWT和插件開發

          主站蜘蛛池模板: 澄城县| 奉化市| 波密县| 巴东县| 明水县| 延长县| 天台县| 苍山县| 邛崃市| 洪江市| 新干县| 樟树市| 唐河县| 罗源县| 武城县| 兴安盟| 台南市| 临汾市| 伊金霍洛旗| 威海市| 娱乐| 达日县| 宝鸡市| 日照市| 甘谷县| 渝北区| 方山县| 白朗县| 沈丘县| 互助| 蒙城县| 阳高县| 和田市| 长治县| 枣庄市| 虹口区| 札达县| 阿克苏市| 澳门| 乡城县| 杭州市|