2016-04-24 90 views
0

我有一個無限的while循環等待SwingUtilities.invokeLaterRunnable接口的事件,但執行沒有繼續...爲什麼?SwingUtilities.invokeLater無限循環,而不是繼續?

//here hello3 prints in cmd but hello2 will not execute 
System.out.println("hello3"); 

//showMessage(); 
SwingUtilities.invokeLater(
    new Runnable(){ 
     public void run() { 
      while(true) { 
       jEditorPane1.setText(s9); 
      } 
     } 
    } 
); 

System.out.println("hello2"); 
+0

從[併發中的Swing]開始(http://docs.oracle.com/javase/tutorial/uiswing/concurrency/)。你正在阻止美國東部時間。 'invokeLater'在將來的某個時間點在EDT上執行'Runnable'方法 – MadProgrammer

回答

3

SwingUtilities.invokeLater將執行事件分派線程中的run方法。

如果所有你告訴我們,被事件派發線程內執行(如果正在一個ActionListener內執行,例如它)的代碼的線程正在成爲「凍結」的無限循環中。

+0

沒有它在任何處理器中使用netbeans形式來設計gui,但它在一個swingutilities.invokelater中生成所有的gui代碼,但是即時通訊創建另一種方法,包括在這個類中的代碼,我將使用從這個類創建的對象調用 – Theon

+0

'Forum_main fm = new Forum_main(); fm.setVisible(true); fm.getdata(uid,tid); 接近();' – Theon

+0

i將類調用看起來像這樣 – Theon