title: Java resize double buffer
body: <p>Currently, I have a <code>Applet</code> running with a while loop inside of it which does two things. </p>
  
  <ul>
  <li>It calls <code>tick()</code> </li>
  <li>Then it calls <code>render(buffer.getGraphics(), getGraphics)</code>. </li>
  </ul>
  
  <p>The buffer is a double buffering image I created by doing the following:</p>
  
  <pre><code>if(buffer == null)
  {
          Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
          buffer = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleVolatileImage(d.width, d.height);
  }
  </code></pre>
  
  <p>Now this works fine, the only problem is when I call <code>setSize()</code> of the applet and <code>JFrame</code>, the new added pixels are just grayed out. Currently I am just creating a new buffer every time the size is changed, but this causes a flickering effect. Anyone know of a way in which I can reuse the existing while using the new area that is added? Thanks</p>