Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

AWT painting problems.  RSS feed

 
John Smitherson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was messing around with AWT and came across a problem that I'm having a hard time understanding. The code below just creates a thread to call repaint 50 times on a canvas object. The canvas just does some simple incremental painting by overriding the update method. The thing that I noticed is when a system-triggered paint event happens (like resizing the frame) it will completely clear the canvas which is not good if I want to do incremental painting. So the solution would be to ignore these events in some way and the Component class has the method setIgnoreRepaint() which
"Sets whether or not paint messages received from the operating system should be ignored. This does not affect paint events generated in software by the AWT"
. Since I believe a Component.repaint() is a app-triggered paint call (generated in the software) the setIgnoreRepaint() shouldn't ignore these repaint() calls on the canvas but it does. So I have to assume that somewhere I'm not reading something correctly? So what is the problem here?



 
Stephan van Hulst
Saloon Keeper
Posts: 6970
109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John, welcome to CodeRanch!

I'm not sure why it's ignoring your repaints. I don't really know AWT well enough. On that note, why are you using AWT at all, and not Swing?

However, a much better way to solve your problem is to paint your scene to a BufferedImage. When you need to do incremental painting, paint everything to the image, and whenever the component needs to be repainted, just draw the part from the image that you need. This can solve lots of potential issues you may have with resizing the frame, or dragging it over the edge of the screen.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!