title: Screen shot of container has black background instead of white
body: <p>I have a small java program with the purpose of taking a screen shot of a specific component with the same program.</p>
  
  <p>Here is an MCVE of it</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Container;
  import java.awt.Dimension;
  import java.awt.Frame;
  import java.awt.Graphics;
  import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  
  import javax.imageio.ImageIO;
  
  @SuppressWarnings("serial")
  public class Screen {
  
      public static void main(String[] args) {
          Frame frame = new Frame("Screen Test!");
          frame.addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent we) {
                  frame.dispose();
               }
           });
  
          Container container = new Container() {
  
              @Override
              public void paint(Graphics g) {
                  super.paint(g);
                  g.setColor(Color.RED);
                  g.fillRect(5, 5, 10, 10);
              }
          };
  
          Dimension dimension = new Dimension(50, 50);
          container.setPreferredSize(dimension);
  
          frame.add(container);
          frame.pack();
          frame.setVisible(true);
  
          BufferedImage bufImage = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_RGB);
          container.paint(bufImage.createGraphics());
  
          File outputfile = new File("image.jpg");
          try {
              ImageIO.write(bufImage, "jpg", outputfile);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>When the code is run it produces this file.</p>
  
  <p><a href="https://i.stack.imgur.com/Tme4d.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tme4d.jpg" alt="Black Background"></a></p>
  
  <p>However, I was expected an output file which looked like this.</p>
  
  <p><a href="https://i.stack.imgur.com/33hFN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/33hFN.jpg" alt="White Background"></a></p>
  
  <p>Have I done something wrong or missed a step?</p>