title: Saving png image with Java using JFileChooser
body: <p>I am trying to save an image that is formed with a BufferedImage.  I get the BufferedImage by doing </p>
  
  <pre><code>(BufferedImage) fg;
  </code></pre>
  
  <p>fg is an image of my jPanel's graphics.  I am successful at saving the image by hardcoding the path in directly as follows:</p>
  
  <pre><code>ImageIO.write((BufferedImage)fg,"png",new File("C:\\Users\\Geiger\\Documents\\test.png"));
  </code></pre>
  
  <p>But when I attempt to add the JFileChooser to the mix the image that is saved comes up being blank with nothing but the jPanel's background color.</p>
  
  <p>My code for my attempt at utilizing the JFileChooser is as follows:</p>
  
  <pre><code>JFileChooser jfc = new JFileChooser();
  int retVal = jfc.showSaveDialog(null);
  if(retVal==JFileChooser.APPROVE_OPTION){
      File f = jfc.getSelectedFile();
      String test = f.getAbsolutePath();
      ImageIO.write((BufferedImage)fg,"png",new File(test));
   }
  </code></pre>
  
  <p>EDIT:To clarify on the issue a little bit more:
  The issue is not that a file doesn't appear its that the graphics don't appear on the image when using the JFileChooser object.</p>
  
  <p>I update my image when the JFrame has a mouse presses event:</p>
  
  <pre><code>fg = jPanel2.createImage(jPanel2.getWidth(), jPanel2.getHeight());
  </code></pre>