title: How do I get the image paint/paintComponent generates?
body: <p>I have a quick question. How do I get the image generated by a JComponent.paint or paintComponent?</p>
  
  <p>I have a JComponent which I use as a 'workspace' and where I have overwritten the paintComponent method to my own. The thing is that my workspace JComponent also has children which has their own paintComponent methods.</p>
  
  <p>So when Swing renders my workspace component, it renders the workspace graphics and then its childrens'.</p>
  
  <p>However, I want to get the image my workspace component generates (which includes the workspace graphics and the children's graphics).</p>
  
  <p>How do I do that?</p>
  
  <p>I tried to call the paintComponent/paint-method myself by using my own Graphics, but i just returned a black image. Here is what i tried;</p>
  
  <pre><code>public void paintComponent(Graphics g) {
  
      if (bufferedImage != null) {
          g.drawImage(bufferedImage, 0, 0, this);
      }
      else {
          g.setColor(Color.WHITE);
          g.fillRect(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight());
      }
  }
  
  public BufferedImage getImage() {
  
      BufferedImage hello = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
      Graphics g = hello.getGraphics();
      paintComponent( g );
  
      return hello;
  }
  </code></pre>
  
  <p>Any thoughts or comments are welcome! :)</p>