62,620
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
JFrame frame = new CustomizedFrame("title");
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new CustomizedFrame("title");
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
if( SwingUtilities.isEventDispatchThread() ) {
// ...
}
if( EventQueue.isDispatchThread() ) {
// ...
}
Runnable r = initTask();
SwingUtilities.invokeLater(r);
Runnable r = initTask();
if( SwingUtilities.isEventDispatchThread() ) {
r.run();
}
else {
try {
SwingUtilities.invokeAndWait(r);
}
catch(Exception ex) {
// ...
}
}