Search code examples
javaperformancegraphics2d

Graphics2D Drawing Performance


I am trying some things out with manually drawing "things" with a Java Graphics2D object within a Swing component and as I reach about >2000 squares that I order the object to draw it gets really slow.

I have no clue whether or not this is "common". Are 2000 objects to render really "a lot"? Is the Graphics2D object just not very performant? Should I just stop where I am now and rather switch to JOGL before I try out more complex stuff and it is too late?


Solution

  • I wrote a Java Spirograph GUI that draws tens of thousands of line segments in 20 milliseconds or less.

    enter image description here

    Make sure you are doing your calculations elsewhere in your application. Your drawing code should do one thing and one thing only: draw.

    However, there is a practical limit to the speed of Graphics and Graphics2D. This Spirograph took 172 milliseconds to draw over 250,000 line segments.

    enter image description here