Java paintComponent告诉是否再次调用 [英] Java paintComponent tell if called again

查看:366
本文介绍了Java paintComponent告诉是否再次调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌搜索了几天,我无法弄清楚如何在我处理paintComponent时调用paintComponent。这个过程漫长而复杂。如果我有第二个(或第三个)绘画请求,我想中止当前的绘制过程并重新开始最近的请求。

解决方案

你不能;调用 paintComponent()排队,阻止



此相关



要获得具体指导,请编辑您的问题以包含最小,完整和可验证的示例显示您修改后的方法。


Been Googling for a few days and I can't figure out how to tell if paintComponent is being called while I'm processing paintComponent. The process is long and complicated. If I have a second (or third) request to paint, I want to abort the current paint process and start over with the most recent request.

解决方案

You can't; calls to paintComponent() are queued, blocking the EDT until completed. Use the approach shown in this AnimationTest to self-time your implementation on a typical target platform. Optimize as required. As a concrete example, this KineticModel illustrates several animation techniques that may apply to your use case.

Addendum: Your update suggests that the "long and complicated" process involves constructing a BufferedImage for later display. To avoid blocking the EDT, do this in the background of a SwingWorker from which you can publish() interim results as they become available. This example simulates building a raster image one line at a time.

This related example constructs a TexturePaint in a similar manner.

For specific guidance, edit your question to include a Minimal, Complete, and Verifiable example that shows your revised approach.

这篇关于Java paintComponent告诉是否再次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆