java - java 是否将多个 repaint() 调用合并为一个 repaint() ?

标签 java timer repaint invokelater

我每秒收到数百个事件,持续几秒钟,每个事件都会更新我的模型。如果我在每个事件之后在 invokeLater() 内部调用 repaint() ,那么 repaint 每秒会被调用数百次吗?它是否足够聪明,能够意识到它有 500 个备份的 repaint() 并且它只需要执行 1 件事? 我不知道事件何时会暂停,但我只想以合理的速度更新 UI。我可以实现一个持续更新的 future,直到有足够长的暂停,比如 500 ms,但如果 java 已经这样做了,那我为什么要这么做呢?

最佳答案

文档是很好的信息来源。

来自repaint()的javadoc :

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.

来自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 to update(). 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.

关于java - java 是否将多个 repaint() 调用合并为一个 repaint() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61473554/

相关文章:

java - Hibernate Criteria 将两个表与第二个表上的条件连接起来,结果是第一个表

c# - Windows 服务内计划中的运行方法

java - 如何在 Swing 中进行某些处理时重新绘制标签?

java - Awt/Swing - 框架在移动过程中不会重新绘制

java - 有没有办法只将特定的 JPanel 区域标记为不透明?

java - 如何从不同级别的 div 定义 xpath

java - 如何在intellij中设置默认的IGNITE_HOME环境变量

java.lang.SecurityException : The Jar (/opt/WebSphere/AppServer7/plugins/com. ibm.ws.security.crypto.jar) 未由受信任的签名者签名

c# - 可移植图书馆中的计时器

ASP.NET定时器: call JS before tick