title: How do you use the Event Dispatch Thread?
body: <p>I learned about how swing isn't thread-safe. Delving deeper, I discovered that every modification to a swing component must be done on the Event Dispatch Thread in order to prevent various issues associated with multithreading. However, the information seemed to completely stop there. There doesn't seem to be a good tutorial that explains how to do this anywhere accessible on the internet.</p>
  
  <p>Patching together information from code posted in relation to other issues, it seemed that I would have to put an untidy block of code around every single swing modification in my program (like this example from my own code):</p>
  
  <pre><code>try {
          SwingUtilities.invokeAndWait(new Runnable() {
  
              public void run() {
                  setTitle("Frame title");
                  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  setVisible(true);
  
                  setSize(800, 480);
                  setLocationRelativeTo(null);
                  setIconImage(Toolkit.getDefaultToolkit().createImage(ClassLoader.getSystemResource("Frame icon.png")));
              }
          });
      } catch (Exception e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>Basically, is this right? Do I have to put that code (or the equivalent with invokeLater) around every modification to a Swing component in my code?</p>
  
  <p>Also, why doesn't Swing do this automatically?</p>