title: Java - How do I get a live preview of a JPanel?
body: <p>I am using the following function to get an initial screenshot of a JPanel.
  How would I set it up to get a live preview of a JPanel?</p>
  
  <pre><code>private static BufferedImage createImage(JPanel panel) {
      int w = 800;
      int h = 550;
      BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
      Graphics2D g = bi.createGraphics();
      panel.paint(g);
      return bi;
  }
  </code></pre>