I know that JPanel is, by default, automatically double-buffered. However, I have a particularly time-intensive painting operation in my panel, but the panel only needs to be repainted when the underlying data changes, which is rare. Therefore, I'd like to reuse the JPanel buffer instead of having it clear after every call to repaint()
.
I've manually implemented a "dirty" flag on my JPanel subclass, but I have no idea how to cancel a paint operation once it's been started. I can't avoid the call to repaint in the first place, since my panel is inside a JScrollPane, which is being repainted every time it's resized (which does happen frequently), which causes my custom panel to be repainted.
Is there any way to do this without manually buffering the panel? If not, what's the recommended method for implementing a manual buffer in conjunction with a JPanel?