Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java swing application not repainting

 
Braden Steffaniak
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java application that should be repainting all the time, however, only repaints once.

heres the method that runs continuously through a infinite loop:



And heres the paintComponent method:



It only prints "testing" once... then never again. On the other hand, it prints "asdf" continuously. What am I doing wrong?
 
Rob Camick
Ranch Hand
Posts: 2600
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can't tell what you are doing wrong based on a few lines of code because we don't know the context of how/when the code is executed.

Maybe your loop is running on the Event Dispatch Thread and you are preventing the frame from repainting itself since the repaint will only be done when the loop is finished executing.

Use a Swing Timer to schedule animation/repainting.

Post your SSCCE that demonstrates the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic