button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (int i = 0; i <5; i++) {
TableItem ti=new TableItem(table, SWT.NONE);
ti.setText(0, "ccccccccc");
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
这样他会过10秒一次性把5条item显示出来
------解决方案--------------------
尝试下面代码看看
- Java code
e.display.syncExec(new Runnable() { @Override public void run() { for(int i=0;i<10;i++){ new TableItem(table, SWT.NONE).setText("ggggg"+i); try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } table.update(); } } });