日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

JFace进度条

發布時間:2025/5/22 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JFace进度条 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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(
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,反復循環的進度條
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中后臺任務的進度條
使用Job建立后臺任務,只需要設置job.setUser(true)進度條就出現了,和上邊一樣,進度條需要自己來控制進度。如果做一個cool的進度條,就看你如何讓進度條顯示出實際的任務進程。 posted on 2007-09-10 13:41 浙林龍哥 閱讀(...) 評論(...) 編輯 收藏

轉載于:https://www.cnblogs.com/huqingyu/archive/2007/09/10/888410.html

總結

以上是生活随笔為你收集整理的JFace进度条的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。