The thing is that the Graphics
context you are using in paintComponent
is created and provided by the caller (the framework), which is also responsible for disposing of it.
You only need to dispose of Graphics
when you actually create it yourself (for example by calling Component.getGraphics()
). In your case, you’re not creating it, you’re just casting it, so do not call dispose in this case.