File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Java swing application not repainting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java swing application not repainting" Watch "Java swing application not repainting" New topic

Java swing application not repainting

Braden Steffaniak

Joined: Jun 03, 2011
Posts: 15
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

Joined: Jun 13, 2009
Posts: 2410
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.
I agree. Here's the link:
subject: Java swing application not repainting
It's not a secret anymore!