同ProgressIndicator一樣,它支持工作的虛擬單位,you need only initialize the ProgressIndicator with the total amount of work you expect to do and notify it as work is completed:
ProgressIndicator indicator = new ProgressIndicator(parent);
...
indicator.beginTask(10);
...
Display.getCurrent()display.asyncExec(new Runnable() {
public void run() {
//Inform the indicator that some amount of work has been done
indicator.worked(1);
}
});
正如上例所示,使用ProgressIndicator需要2步:
1.讓indicator知道總共有多少工作,通過使用beginTask().只有這個(gè)方法被調(diào)用了之后,這個(gè)control才會(huì)在屏幕上顯示。
2.每當(dāng)有一部分工作被完成了,就調(diào)用worked()。為了防止非ui的線程來update widgets,所以使用asyncExec()來解決這個(gè)問題。
ProgressIndicator也提供animated模式,即總工作量不知道的情況。在這種模式下,the bar continually fills and empties
until done() is called. 要使用這個(gè)模式,就要用beginAnimatedTask()代替beginTask();并且不需要worked()方法了
posted on 2006-04-10 18:07
JOO 閱讀(586)
評(píng)論(0) 編輯 收藏 所屬分類:
SWT & JFace IN ACTION