What you need to do is to inform the swing component whenever you know that part of the image on your panel changed. The normal way to do this is to, as you said, call repaint()
and if you know the rectangle that was 'invalidated' you can also indicated that.
Depending on the events that cause the contents of the JPanel
, you need to change your application design so that the presentation part of your application 'listens' to changes in the data underneath and repaints when these changes occur.
There is another method called paintImmediately()
which might do for certain situations, but you have to describe a little more your scenario and in which cases are you needing to repaint continuously.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…