Search code examples
javagraphicspaintrepaintmanager

When the Graphics instance is created


I know that when paint is happening an instance of the Graphics class should be created. That Graphics object (Actually Graphics2D object) is going through paint() method and all the details that should be printed or updated on the screen are stored in that object.

As I know of this process is handled by RepaintManager when user called repaint() method or when repaint is needed to the UI. So, a Graphics instance has to be created to store the information regarding the painting.

As this process is handled by RepaintManager, I thought that the Graphics instance is also initialized inside RepaintManager. But I found source code of RepaintManager recently. And couldn't find a place that a new Graphics instance is created.

So, is it really created inside RepaintMananger or anywhere else..?
Thanks..


Solution

  • It's created in Component.getGraphics() see the API for more information