I am building a swing interface for drawing overlays over a particular image. I have found several examples of how to draw an image on a JPanel, and I am able to do this without difficulty. However, I would like to keep this image completely static while dynamically drawing overlays on top of it. With that in mind, it would be better if I could set the image as a permanent background of the panel, rather than having paintComponent()
redraw the image every time. This would be particularly useful, as there will frequently be situations where I want to removeAll()
graphics currently on the panel and redraw new ones.
So my question is this: is there a way to set a permanent background image in JPanel, or do I have to redraw the image every time paintComponent()
is called?