在 awt 中单独重绘

发布于 2024-11-15 00:48:10 字数 248 浏览 1 评论 0原文

“AWT 和 Swing 中的绘画”文档说明了以下内容。

“如果在处理初始重绘请求之前组件上发生对 repaint() 的多次调用,则多个请求可能会折叠为对 update() 的单个调用。”

是否可以更改此行为以便多个重绘调用永远不会折叠成单个调用?

编辑:文档进一步指出,“确定何时应折叠多个请求的算法取决于实现。”

我的问题是我在一个移动平台上进行单独的重绘调用,并且我试图在桌面上复制该行为。

The "Painting in AWT and Swing" docs state the following.

"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()."

Is it possible to change this behavior in a component so that multiple calls to repaint never get collapsed into a single call?

EDIT: The docs further state this, "The algorithm for determining when multiple requests should be collapsed is implementation-dependent."

My problem is I'm on a mobile platform that does separate calls to repaint and I'm trying to replicate the behavior on the desktop.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贩梦商人 2024-11-22 00:48:10

我猜您有一些长时间运行的任务正在循环,并且没有按照您的预期更新 GUI。这是因为您阻塞了事件调度线程,因此 Swing 无法重新绘制自身。

阅读 Swing 教程中有关 Swing 中的并发 的部分。使用 SwingWorker 来执行长时间运行的任务,这样您就不会阻塞 EDT,然后您可以发布结果和所需的结果,并且它们将按预期绘制。

或者,如果您的问题出在动画上,请使用 Swing Timer。本教程还有关于计时器的部分。

I'm guessing you have some long running task that is looping an not updating the GUI as you expect it to. This would be because you are blocking the Event Dispatch Thread so Swing can't repaint itself.

Read the section from the Swing tutorial on Concurrency in Swing. Use the SwingWorker for the long running task to you don't block the EDT and then you can publish results and required and they will be painted as expected.

Or if you problem is with animation, then use a Swing Timer. The tutorial also has a section on timers.

烟燃烟灭 2024-11-22 00:48:10

我担心绘制算法在 swing/awt 中是相当硬编码的,并且它们只为不同的目的提供不同的钩子。您可以使用 这个 swing 方法可以提供你想要的,但遗憾的是似乎没有 awt 等效项。您可以尝试混合 awt/swing,但通常不建议这样做,并且在某些情况下可能会导致奇怪的行为,因为我听到

PS:对于询问为什么您想要这个的人:某些应用程序(主要是游戏)需要同步重绘以确保它们的视觉外观与内部状态保持一致 - 例如,JScrollbar 也在内部使用它(我还没有查看相关代码,所以对此持保留态度 - 我确实理解为什么它在那个特定的 案件)

I fear the paint algorithm is pretty hardcoded in swing/awt and they only offer different hooks for different purposes. You can use use this method in swing which would offer what you want, but sadly there doesn't seem to be an awt equivalent. You could try mixing awt/swing, but that's usually not recommended and may lead to strange behavior in some cases as I hear

PS: And for people asking WHY you'd want this: Some apps (mostly games) need synchronous redraws to ensure that their visual appearance keeps up with the internal state - afaik the JScrollbar also uses it internally for example (I haven't looked at the code in question, so take this with a grain of salt - I do understand though why it could be useful in that particular case)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文