Swing是單線程事件分發(fā)機制來處理界面響應的,如果只是想等待一段時間然后刷新界面可以這樣:outPrint.setText("其他地方數(shù)據(jù)正在清空...");EventQueue.invokeLater(newRunnable(){Thread.sleep(3000);outPrint.repaint();});如果要做一個比較耗費時間的操作,最好還是用SwingWorker類通過SwingWorker的doInBackground()方法處理費時間的任務,調(diào)用publish(...)把中間數(shù)據(jù)發(fā)布出來使得process方法可以接收到;方法process(...)來做中間數(shù)據(jù)的處理;方法done()來做任務結(jié)束后的界面更新。/***假設用來更新進度條,進度條的滿值為100*@ClassName:SimActivity*@Description:TODO**/privateclassSimActivityextendsSwingWorker{privateintcurrent=0;privateinttarget=0;publicSimActivity(inttarget){this.target=target;}@OverrideprotectedVoiddoInBackground()throwsException{//這里執(zhí)行耗時的操作,例如讀取文件try{while(currentThread.sleep(100);current++;publish(current);}}catch(InterruptedExceptione){}returnnull;}@Overrideprotectedvoidprocess(Listchunks){for(Integerchunk:chunks){//進度條設置值processBar.setValue(chunk);}}@Overrideprotectedvoiddone(){//完成后的清理工作例如刷新界面或者改變某些組件的狀態(tài)等}}