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