3 Replies Latest reply on Feb 5, 2012 12:08 PM by 892826

    How to set the background of a JPanel with it’s previous content?

      I have a JFrame containing some JPanels. Out of all JPanel, one JPanel has a Graphics object (Graphics g) with paintComponent method to paint a Graphics2D image in that JPanel. After complete painting i want don't want to paint the same thing again and again (repaint() does it for me automatically). I want to set this final generated image to the background of the JPanel.

      I have an idea, but i want to discuss it. What i can do is, after completing the image, i can use
      BufferedImage screenShot = newRobot().createScreenCapture(rectangle);
      to the screenshot of JPanel with specified rectangle. After that i can set this BufferedImage to the JPanel. Is it correct way? or should it require modifications?

      Thank you.