flicker : Java Glossary

flicker
Here are some things to try to avoid flicker:
  1. In a Canvas.paint(), there is no need to call super. paint() since update() will have already cleared the screen.
  2. In your update routine, don’t erase anything, just call paint. paint then must paint the entire Canvas. You override update() to just directly call paint() without the g. clearRect(0, 0, width, height);.
  3. In your update routine, just erase the parts of the image that will become background, perhaps even only the parts that are not already background.
  4. Use Swing which has double buffering built-in. You must override paintComponent rather than paint to get the automatic double buffering. Oddly, sometimes turning double buffering off with JComponent. setDoubleBuffered( false ) might help.
  5. Use manual double buffering in AWT (Advanced Windowing Toolkit). Prepare all your images ahead of time with createImage and blast them to the screen (without erasing first) with drawImage in your paint routine. Because Images are platform dependent, you can’t simply instantiate them with a constructor. You have to create them through calls like Applet.getImage(), Component. createImage(), or Toolkit. getDefaultToolkit(). getImage().
  6. In Windows, in Swing, you will see the entire screen repaint from time to time for no apparent reason, causing an annoying flicker. This is due to the fact that Swing uses DirectDraw for rendering which periodically redraws just to be safe. You can turn off DirectDraw and use standard Windows GDI (Graphics Device Interface) rendering by starting
    Java.exe -Dsun.java2d.noddraw=true MyClass
    This will slightly slow down painting, however.
  7. In Swing, use setOpaque( true ) to arrange for the system to draw the background in for you. This seems to work better than drawing it yourself with clearRect.
  8. If you tie up the Swing thread, it can never get around to processing events and updating the screen. If you have entensive computation, start up a background thread and do your GUI (Graphic User Interface) work via SwingUtilities.invokeLater, or EventQueue.invokeLater.
This is a complicated topic. Tricks for AWT and Swing differ.

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/flicker.html J:\mindprod\jgloss\flicker.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.210]
You are visitor number 21,677.