title: JFrame to image without showing the JFrame
body: <p>I am trying to render a JFrame to an image without ever displaying the JFrame itself (similar to what <a href="https://stackoverflow.com/questions/9279330/saving-jframe-to-image">this</a> question is asking). I have tried using this piece of code:</p>
  <pre><code>private static BufferedImage getScreenShot(Component component)
  {
      BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
      // call the Component's paint method, using
      // the Graphics object of the image.
      component.paint(image.getGraphics());
      return image;
  }
  </code></pre>
  <p>However, this only works when the <code>JFrame</code>'s <code>setVisible(true)</code> is set. This will cause the image to be displayed on the screen which is not something I want. I have also tried to create something like so:</p>
  <pre><code>public class MyFrame extends JFrame
  {
      private BufferedImage bi;
  
      public MyFrame(String name, BufferedImage bi)
      { 
           this.bi = bi;
           super(name);
      }
  
      @Override
      public void paint(Graphics g)
      {
           g.drawImage(this.bufferedImage, 0, 0, null);
      }
  }
  </code></pre>
  <p>This however displays black images (like the code above). I am pretty sure that what I am after is possible, the problem is that I can't really find how. My experience with custom Swing components is pretty limited, so any information will be appreciated.</p>
  <p>Thanks.</p>