Rob Camick wrote:If you do need to do custom painting for some reason, you should never read the image in the paintComponent() method. This method is called many time when Swing determines a component needs to be repainted.
Surprised, I thought overriding the paintComponent() method was the standard way to put graphics in a JPanel? I'm following the example on p 365 of Head First
Java, which is where I got this from.
Say I have a slightly more complex example where I want to paint a red spot on my image - I'd need to override paintComponent() then? In this case, how do I get my JFrame to fit my JPanel?
Which produces this:
which expands to: