This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Other JSE/JEE APIs and the fly likes Graphics 2D and Components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Graphics 2D and Components" Watch "Graphics 2D and Components" New topic
Author

Graphics 2D and Components

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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?


GenRocket - Experts at Building Test Data
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
Don't get me started about those stupid light bulbs.
 
subject: Graphics 2D and Components