I am receiving hundreds of events per second for a few seconds, each updates my model. If I call repaint()
inside of invokeLater()
after every event, will repaint be called hundreds of times per second? Is it smart enough to realise that it has 500 backed up repaint()
and it only has to do 1?
I do not know when the events will pause, but I want to update the UI only at a reasonable rate. I can implement a future that keeps getting updated until there is a long enough pause, say 500 ms
, but if java already does that, then why should i?
The documentation is such a good source of information.
From javadoc of repaint()
:
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.
From Painting in AWT and Swing
The program invokes
repaint()
on the component, which registers an asynchronous request to the AWT that this component needs to be repainted.The AWT causes the event dispatching thread to invoke
update()
on the component.NOTE: If multiple calls to
repaint()
occur on a component before the initial repaint request is processed, the multiple requests may be collapsed into a single call toupdate()
. The algorithm for determining when multiple requests should be collapsed is implementation-dependent. If multiple requests are collapsed, the resulting update rectangle will be equal to the union of the rectangles contained in the collapsed requests.