title: Best to handle 2 overlaying live updated panels?
body: <p>In very basic terms I have a panel that is drawing a line pixel by pixel and is being updated in real time. On top of this I want another panel that draws a box around the current pixel but clears itself later. Both are in real time</p>
  
  <p>My current situation is a wrapper JPanel that has an <code>OverlayLayout</code>. The bottom panel has the line that is drawn with the <code>Graphics2D</code> object fetched from its <code>JPanel</code>. The top panel the box that follows around that is also drawn with the Graphics2D object fetched from its <code>JPanel</code>.</p>
  
  <p>The issues in this system are many. Since I'm just drawing on the <code>Graphics2D</code> object separately and not overriding the JPanel's <code>paint()</code> not only is all the lines lost when the panel needs to repaint, I think I'm going against Swing's threading model by only having a single thread update the screen. I have also not gotten the top panel to work correctly, it just keeps clearing the screen and won't let the bottom panel draw a line.</p>
  
  <p>What would be the best way to approach this situation? I have little experience with image processing and the low-level displaying of images in Swing, I just know the basics. I've heard of <code>BufferedImage</code>, but not knowing where to put that image, if it will be updated when changed later, the efficiency of doing that, and the fact that its buffered scare me off. I'm not sure what to use</p>
  
  <p>Can someone point me in the right direction of what I need to use to accomplish this? </p>