February 28, 2009

Applet ProgressBar Flickering Issue

I had recently taken the the time to convert my EpicGame Code from VB to java, so I could make an applet that could be played online. (I was lazy and did not want to make it flash based) However after finishing it and testing on the mac side I though I was finished. Yet, later I started hearing complaints of the game flickering, I was confused as it worked fine for me and as usual I had double buffering setup, which in theory would prevent any flickering. Still, for some reason Window's version Java would flicker uncontrollably. I spent several hours trying different graphics buffering setups and also drawing to separate panels, but with no success.

Luckily I randomly stumbled onto the problem, it was the JProgressBars that I was using. When you update a value in the progress bar it calls the update method that then calls paint, which would happen concurrently mid screen refresh and draw a blank white screen, which was the rouge flickering.

So on Windows do not use JProgressBars with animation as it messes it up, or you need to extend the class and override the setValue method so it does not update the UI. Oh, and of course on the Mac side it all works flawlessly from the start.

No comments: