zoukankan      html  css  js  c++  java
  • JFace进度条

    最近在做一个小程序,它会长时间等待,需要一个进度条了。

    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的进度条,就看你如何让进度条显示出实际的任务进程。
  • 相关阅读:
    ionic入门教程第十二课-通用模块的分离$ionicModal
    ionic入门教程第十一课-简要说明ion-list、ion-item完成列表页ion-infinite-scroll上拉加载ion-refresher下拉刷新
    ionic入门教程第十课-接着说说ion-slide-box和它的注意事项、slide-tabs
    ionic入门教程第九课-开始动手做项目吧!ion-nav-bar、ion-nav-buttons、ion-tabs
    ionic入门教程第八课-(加更)从无到有说Ionic、画图说明MVC-U-S
    ionic入门教程第七课-简要说明几种界面之间的参数传递及优缺点
    ionic入门教程第六课-从服务器请求数据的几种方式$http.get()、jsonp()分别和callback、$q的组合
    Java 8 API Stream让List操作更便捷
    程序员常用linux命令ls,ll,cd,more,tail,rm,mv,find,vi,mdir,touch,ps,kill详解
    java数组插入排序代码详解
  • 原文地址:https://www.cnblogs.com/huqingyu/p/888410.html
Copyright © 2011-2022 走看看