update(getGraphics()) vs. repaint()
Posted on 2000-05-03
I have seen top experts (espesially heyhey_) saying many times never to use getGraphics() to paint. I am having a small problem with my current application and I think the easiest way to solve it would be the following portion of code:
Graphics g = myComponent.getGraphics();
but respecting their opinion I would like an explanation on why I shouldn't use it.
The problem with repaint() occurs when for example I have a long and costly (takes a lot of CPU time) process that needs to inform a progress bar about its progress. If I update the value of the progress bar and call repaint() it will only end up repainting after the process is over and so the progress bar becomes useless. Calling update(getGraphics()) seems like the easiest and clearest way out of this.