4

With swing is it granted that conversion

paint (Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    ......
}

will always work? Or there could be different graphics implementations, not only Graphics2D?

michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
  • 1
    See this question: http://stackoverflow.com/questions/179415/java2d-is-it-always-safe-to-cast-graphics-into-graphics2d – Enwired Jul 10 '12 at 16:50

1 Answers1

3

Short answer is, yes it should work, unless you're using some other JVM. I can't remember since when exactly, but Swings paint engine will always use a Graphics2D instance to perform its component painting

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366