【发布时间】:2019-12-26 19:47:12
【问题描述】:
我正在尝试编写包含按钮和标签的代码。
我想,当用户单击按钮时,标签显示 TEXTA,然后在三秒钟后显示 TEXTB。 我看到的是当我单击按钮时,标签等待 3 秒并显示 TEXTB。 这是我的代码:
Label lblFindModem = new Label(shell, SWT.NONE);
lblFindModem.setFont(SWTResourceManager.getFont("Ubuntu", 13, SWT.NORMAL));
lblFindModem.setBounds(329, 164, 256, 28);
lblFindModem.setText("Modem is not Initialized");
Button btnFindModem = new Button(shell, SWT.NONE);
btnFindModem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
System.out.println("Someone Clicked the button");
lblFindModem.setText("Unplug the modem for 3 seconds...");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
lblFindModem.setText("Plug the modem again.");
}
});
【问题讨论】:
-
如果 UI 线程在 swing 或 Eclipse RCP 中,您不能简单地使用睡眠。
标签: java swt delay windowbuilder