0
我遇到問題。在我的(蝕4爲基礎)GUI我有兩個目的:進度條未及時更新
Button button = new Button(groupInitialize, SWT.NONE);
ProgressBar bar= new ProgressBar(group, SWT.SMOOTH);
予設定的聽者的按鈕,使得該按鈕被按下的闡述的任何時間開始。在此詳細說明中,狀態欄必須更新。
// Button listener definition!
button .addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(final Event event) {
Runnable run = new Runnable() {
@Override
public void run() {
Display display = PlatformUI.getWorkbench().getDisplay();
display.asyncExec(new Runnable() {
public void run() {
myLongLastingMethod();
}
});
}
};
new Thread(run).start();
}
});
,這就是我在myLongLastingMethod()做的事:
private void myLongLastingMethod() {
action1();
update();
action2();
update();
action3();
update();
}
最後更新方法(-should-更新進度條):
修訂
private void update() {
if (progressBar.isDisposed()) {
return;
}
int selection = progressBar.getSelection();
progressBar.setSelection(++selection);
}
我敢肯定我做錯了什麼...任何我dea /幫助爲什麼它不應該工作?
這樣的:公共無效的handleEvent(最終事件的事件){myLongLastingMethod();} ? – Kasper
不,你仍然需要運行後臺線程,添加代碼來回答。 –
好吧我知道了,但仍然不能正常運行,我們不在UI線程中(事實上我得到了一個異常)。 – Kasper