JFace进度条
JFace進(jìn)度條 最近在做一個(gè)小程序,它會(huì)長(zhǎng)時(shí)間等待,需要一個(gè)進(jìn)度條了。
1,普通的進(jìn)度條
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(500,?375);
????????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(true,?true,?runnable);
????????shell.open();
????????shell.layout();
????????while?(!shell.isDisposed())?{
????????????if?(!display.readAndDispatch())
????????????????display.sleep();
????????}
????}
}
2,反復(fù)循環(huán)的進(jìn)度條
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(500,?375);
????????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(true,?true,?runnable);
????????shell.open();
????????shell.layout();
????????while?(!shell.isDisposed())?{
????????????if?(!display.readAndDispatch())
????????????????display.sleep();
????????}
????}
}
3,rcp中后臺(tái)任務(wù)的進(jìn)度條
使用Job建立后臺(tái)任務(wù),只需要設(shè)置job.setUser(true)進(jìn)度條就出現(xiàn)了,和上邊一樣,進(jìn)度條需要自己來控制進(jìn)度。如果做一個(gè)cool的進(jìn)度條,就看你如何讓進(jìn)度條顯示出實(shí)際的任務(wù)進(jìn)程。 posted on 2007-09-10 13:41 浙林龍哥 閱讀(...) 評(píng)論(...) 編輯 收藏
Swt/Jface進(jìn)度條
處理長(zhǎng)時(shí)間的任務(wù)的時(shí)候常需要進(jìn)度條顯示,有幾種實(shí)現(xiàn)方式1,普通的進(jìn)度條
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(500,?375);
????????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(true,?true,?runnable);
????????shell.open();
????????shell.layout();
????????while?(!shell.isDisposed())?{
????????????if?(!display.readAndDispatch())
????????????????display.sleep();
????????}
????}
}
2,反復(fù)循環(huán)的進(jìn)度條
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(500,?375);
????????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(true,?true,?runnable);
????????shell.open();
????????shell.layout();
????????while?(!shell.isDisposed())?{
????????????if?(!display.readAndDispatch())
????????????????display.sleep();
????????}
????}
}
3,rcp中后臺(tái)任務(wù)的進(jìn)度條
使用Job建立后臺(tái)任務(wù),只需要設(shè)置job.setUser(true)進(jìn)度條就出現(xiàn)了,和上邊一樣,進(jìn)度條需要自己來控制進(jìn)度。如果做一個(gè)cool的進(jìn)度條,就看你如何讓進(jìn)度條顯示出實(shí)際的任務(wù)進(jìn)程。 posted on 2007-09-10 13:41 浙林龍哥 閱讀(...) 評(píng)論(...) 編輯 收藏
轉(zhuǎn)載于:https://www.cnblogs.com/huqingyu/archive/2007/09/10/888410.html
總結(jié)
- 上一篇: 无敌的广告
- 下一篇: 一步一步SharePoint 2007之