• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Graphics 2D and Components

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there any 3rd party components out there that let you issue Graphics2D drawing commands outside of the paint() method? Or are we always stuck with overriding this method and issuing all commands there?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you have to do is cast getGraphics() to Graphics2D and use it normally. However, it's always better to do this in the paint method because that's what gets called in the redraw loop built in to Swing.

I guess you could create a BuffedImage to draw to and have the component reference the same BufferedImage in it's paint() method. You'd still have to remember to call repaint() every time you made changes, though...



If you explain what exactly are you trying to do I might be able to offer more direction.
 
reply
    Bookmark Topic Watch Topic
  • New Topic