invokeLater() 메소드가 정적 입니다. SwingUtilities 메소드 클래스를 사용하여 비동기적으로 작업을 수행할 수 있습니다. AWT 이벤트 디스패처 스레드 . SwingUtilities.invokeLater() 메소드는 SwingUtilities.invokeAndWait() 처럼 작동합니다. 이벤트 대기열에 요청을 넣는 것을 제외하고 즉시 반환 . invokeLater() 메소드는 Runnable 내부의 코드 블록을 기다리지 않습니다. 대상 이 추천한 실행합니다.
구문
public static void invokeLater(Runnable target)
예시
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class InvokeLaterTest extends Object {
private static void print(String msg) {
String name = Thread.currentThread().getName();
System.out.println(name + ": " + msg);
}
public static void main(String[] args) {
final JLabel label= new JLabel("Initial text");
JPanel panel = new JPanel(new FlowLayout());
panel.add(label);
JFrame f = new JFrame("InvokeLater Test");
f.setContentPane(panel);
f.setSize(400, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);
try {
print("sleeping for 5 seconds");
Thread.sleep(5000);
} catch(InterruptedException ie) {
print("interrupted while sleeping");
}
print("creating the code block for an event thread");
Runnable setTextRun = new Runnable() {
public void run() {
try {
Thread.sleep(100);
print("about to do setText()");
label.setText("New text");
} catch(Exception e) {
e.printStackTrace();
}
}
};
print("about to call invokeLater()");
SwingUtilities.invokeLater(setTextRun);
print("back from invokeLater()");
}
} 출력

main: sleeping for 5 seconds main: creating the code block for an event thread main: about to call invokeLater() main: back from invokeLater() AWT-EventQueue-0: about to do setText()
