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