当您执行繁重的任务时,应在另一个线程中运行它们,而不是与gui相同。如果您在“
事件调度线程”中运行,则该GUI将冻结直至完成。
您可以使用SwingWorker,这是一个示例,我真的很喜欢Swing
Worker示例
例:
class Worker extends SwingWorker<String, Object> { @Override protected String doInBackground() throws Exception { //here you send the mail return "DONE"; } @Override protected void done() { super.done(); //this is executed in the EDT JOptionPane.showMessageDialog(null, "Message sent", "Success", JOptionPane.INFORMATION_MESSAGE); }}


