title: java.awt.EventQueue.invokeLater explained
body: <p>I am very curious why do we have to use <code>java.awt.EventQueue.invokeLater</code> to control swing components.</p>
  
  <p>Why can't we do that in normal thread? What exactly is going on behind the scenes? From what I have noticed if I have a <code>JFrame</code> I can set visibility to true or false from the main thread without getting any errors, and it does seem to work. So what exactly do I achieve by using <code>java.awt.EventQueue.invokeLater</code>? I am also fully aware that I can use <code>SwingUtilities.invokeLater</code> but as <a href="https://stackoverflow.com/questions/8847083/swingutilities-invokelater-vs-eventqueue-invokelater">explained here</a>, they seem to be one and the same thing.</p>
  
  <p>Thanks to anyone for their explanation. Hopefully this is a valid question.</p>
  
  <p>EDIT: to answer wumpz question
  We can create a jframe</p>
  
  <pre><code>JFrame frame = new JFrame("Hello world");
  frame.setSize(new Dimension(300, 300));
  frame.setPreferredSize(new Dimension(300, 300));
  frame.setMaximumSize(new Dimension(300, 300));
  frame.setMinimumSize(new Dimension(300, 300));
  frame.setVisible(true);
  frame.pack();
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  </code></pre>
  
  <p>And on the same thread it was created do the following.</p>
  
  <pre><code>for (int i = 0; i &lt; 34; i++)
  {
      System.out.println("Main thread setting to "+(!frame.isVisible()));
      frame.setVisible(!frame.isVisible());
  }
  </code></pre>
  
  <p>And no complaints.</p>