• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use repaint?  RSS feed

 
Billy Sang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Am I using the repaint method properly. It doesn't seem to work. It works ii I use it only once without repeating. Am I not getting something here?

I found this on Oracle's site after some research:
"
NOTE: If multiple calls to repaint() occur on a component before the initial repaint request is processed, the multiple requests may be collapsed into a single call to update(). The algorithm for determining when multiple requests should be collapsed is implementation-dependent. If multiple requests are collapsed, the resulting update rectangle will be equal to the union of the rectangles contained in the collapsed requests. "

Does this have anything to do with my problem? If so, how do fix this. Thanks for any help.
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code from any listener executes on the Event Dispatch Thread (EDT). All Swing painting is done on the EDT. If you tell the EDT to sleep (for one second), then the EDT cant paint the changes. So the only painting that is done is the last iteration of your loop.

If you want to do animation of some kind then you should be using a Swing Timer to schedule an event to happen every second. Then you will see the painting done each second.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!