I'm pretty new to the java draw functions, but I have a sample histogram that I build. on button click, i have it rebuilding the histogram with random values. However, every time i hit the button to repaint, i get a black flash before it redraws. I remember hearing this was pretty common and the fix had something to do with buffering. Any advice?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The first thing you do when you draw is clear your canvas. The flash you see is the blank canvas as things get drawn. If you were to slow it down fast enough, you would see each thing appear on the screen, one at a time.
You can get around this by what's called double buffering.
You paint your screen to an off-screen image. Then you paint your image to the screen all at once.
回答2:
Swing is double buffered by default.
Read the section from the Swing tutorial on Custom Painting for working examples.