title: Multiple independent layers in Graphics
body: <p>Is it possible to have multiple independent drawing layers using <code>Graphics</code>? I actually need two layers (like in Photoshop, Gimp, Paint.NET, ...) on which I can draw objects and I want all objects of the top layer appear above all objects of the bottom layer, independent of the order in which objects are drawn. It is not the case that I can first draw all objects of one layer and then draw all objects of the other.</p>
  
  <p>Example: </p>
  
  <ol>
  <li>draw red filled circle on bottom layer</li>
  <li>draw green rectangle on top layer</li>
  <li>draw red filled rectangle on bottom layer</li>
  <li>draw green circle on top layer</li>
  </ol>
  
  <p>Desired result: the two empty green objects should be rendered above the two filled red objects.</p>
  
  <p>I fiddled around using <code>JLayeredPane</code> and <code>Canvas</code> and the closest I could get was a <code>Canvas</code> on top of a <code>JComponent</code> but unfortunately the <code>Canvas</code> background cannot be transparent, so everything that is drawn in the <code>JComponent</code> is covered by the <code>Canvas</code> background.</p>
  
  <p>Can you tell me how to achieve this (if it's possible after all)?</p>