Reputation: 608
When running a program that makes a JFrame (Swing), why is it that if it runs on thread 0 it does not show the window? Running on thread 0 can be done by (OS X):
java -XstartOnFirstThread Driver
Example
public class Driver
{
public static void main (String args[])
{
SwingUtilities.invokeLater(() -> {
WindowClass button = new WindowClass(450, 450);
});
}
}
public class WindowClass extends JFrame
{
public WindowClass(int width, int height)
{
setTitle("Demo");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(width, height);
setVisible(true);
}
}
Upvotes: 0
Views: 138
Reputation: 285415
You need to show code, but you run code on the EDT by queuing it on the EDT using SwingUtilities:
SwingUtilities.invokeLater(() -> {
// start your GUI here
});
Upvotes: 1