For some UI components in our application, we override paintComponent
, which under some conditions \"recursively\" calls itself by invoking repaint
Is this a good practice (especially in terms of performance / efficiency / CPU usage)?
No, it is not good practice. Calling repaint from within paintComponent
is bad practice because:
Is it better to use a Timer or a background thread to repaint our components?
Yes, using a Timer
or Thread
gives you much better control over the frame rate, without bogging down the EDT while doing so. Depending upon the context, a Timer
runs on the EDT (as opposed to a Thread) so no dispatching to the EDT is required.