I found something strange in the paintComponent method. When I put 'System.out.println("1") ; in the paintComponent method, 1 was output Three times in the console window. As far as I've looked into it, the paintComponent method runs many timesenter image description here. I wonder why.
Asked
Active
Viewed 60 times
0
-
4Does this answer your question? [How does paintComponent work?](https://stackoverflow.com/questions/15544549/how-does-paintcomponent-work) – flaxel Oct 02 '20 at 17:19
-
1nsj247, in general its preferred to include code in your question instead of images of code. You can see some reasons why on this meta answer https://meta.stackoverflow.com/a/285557/2754938 – Tyler Oct 02 '20 at 17:37
1 Answers
0
paintComponent
gets run a lot. For example, Every time the JComponent is resized, shown, validated from an invalid state, and when repaint() is called. This functionality exists so that Components can change their display dynamically as things change, rather than being static in display like an image

ControlAltDel
- 33,923
- 10
- 53
- 80