Theon
Theon

Reputation: 9

SwingUtilities.invokeLater with infinite loop, not continuing?

I have an infinite while loop waiting for an event in SwingUtilities.invokeLater with Runnable interface but the execution is not continuing ... why?

//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");

Upvotes: 0

Views: 590

Answers (1)

Paco Abato
Paco Abato

Reputation: 4065

SwingUtilities.invokeLater will execute the run method inside the event-dispatching thread.

If all the code that you show us is being executed inside the event-dispatching thread (if it is being executed inside an actionListener for example) the thread is becoming "frozen" inside the infinite loop.

Upvotes: 3

Related Questions