我正在为 MAC OS 开发一个 SWT java 项目,我需要在 SWT UI 上添加一个标签,我必须在其中显示当前时间,每秒更新一次。我试过了,即
final Label lblNewLabel_1 = new Label(composite, SWT.CENTER);
FormData fd_lblNewLabel_1 = new FormData();
fd_lblNewLabel_1.left = new FormAttachment(btnNewButton_call, 10);
fd_lblNewLabel_1.bottom = new FormAttachment(100, -10);
fd_lblNewLabel_1.right = new FormAttachment(btnTransfer, -10);
fd_lblNewLabel_1.height = 20;
lblNewLabel_1.setLayoutData(fd_lblNewLabel_1);
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
while(true){
lblNewLabel_1.setText(Calendar.getInstance().getTime().toString());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
但它不起作用,请帮我这样做。提前致谢。