Java Applet、AWT 刷新、Mac OS X 10.4 上的问题

发布于 2024-07-06 13:07:55 字数 1383 浏览 11 评论 0原文

我们有一个使用 AWT 构建的 Java Applet。 该小程序允许您从硬盘中选择图片并将其上传到服务器。 该小程序包含一个可滚动的图片列表,在 Windows、Linux 和 Mac OS X 10.5 中运行良好。 我们通过 Java Web Start 或在网页内启动此小程序。

无论 Java 版本(1.4 或 1.5)如何,我们的小程序在 Mac OS X 10.4 中都无法正常运行。 您可以在此处找到滚动时不正确行为的屏幕截图:

http://www.lavablast .com/tmp/ui_error.png

简而言之,有时滚动图片时最终会与应用程序的页眉或页脚重叠。 此行为不会发生在其他平台上。 在 Mac OS X 10.4 上,滚动时它会在错误的位置显示图片,如果在该位置绘制图像后刷新屏幕,情况还不错。 然而,应用程序似乎并不知道它绘制得不正确,因此不会刷新。

如果窗口最小化、调整大小甚至移动,应用程序将刷新,位置不正确的元素消失,应用程序将恢复正常。 我花了相当长的时间试图强制刷新背景图像,但没有成功。 (直接重新绘制图像,重新绘制几个面板的所有子面板等)因此,我正在寻找任何可以帮助我在 Mac OS X 10.4 下解决此问题的提示,或者在最坏的情况下,简单地模拟完整的小程序刷新。

直到最近,所有内容都与 Java 1.1 兼容,但在一些位置发生了变化,现在需要 1.4。 我不认为这些更改造成了问题,我只是将其作为额外信息提供。 如果您对滚动面板的实现细节感兴趣,我将进行调查,但我假设这是一个常见的平台错误,必须了解解决方法。

要重现该问题,请打开以下 Java Web Start 应用程序: http://www.lavablast.com/tmp/opal-webstart.php。 jnlp

选择一个包含大量图像的文件夹并使用滚动条进行播放。 在某个时刻(相当快),您应该会遇到刷新问题。

编辑:我遵循此处的第一个建议,并将所有具有背景图像的控件替换为 Swing 等效控件,但问题仍然存在。 (另外,我还需要进行许多其他修复才能进行彻底的更改)。 还有其他想法吗? 强制完全刷新的简单一行代码会很棒:)

Edit2:主线程创建面板并启动 X 线程。 使用观察者/通知者模式,线程完成并通知主控件,主控件将面板添加到页面。 这是通过 EventQueue.invokeLater 完成的,除非我弄错了,否则它应该在正确的线程上运行。 即使没有额外的线程正在运行(如在加载期间),滚动时问题也最为严重。

We have a Java Applet built using AWT. This applet lets you select pictures from your hard drive and upload them to a server. The applet includes a scrollable list of pictures, which works fine in Windows, Linux and Mac OS X 10.5. We launch this applet via Java Web Start or within a web page.

Our applet does not behave properly in Mac OS X 10.4, regardless of the version of Java (1.4 or 1.5). You can find a screenshot of the incorrect behaviour, when scrolling, here:

http://www.lavablast.com/tmp/ui_error.png

Simply put, sometimes when scrolling the pictures end up overlapping the header or footer of the application. This behaviour does not occur on other platforms. On Mac OS X 10.4, it shows the pictures in the incorrect location when scrolling, which would not be so bad if it refreshed the screen after painting the image at that location. However, it does not appear that the application knows it painted it incorrectly and thus does not refresh.

If the window is minimized, resized or even moved, the application is refreshed and the incorrectly positioned elements vanish and the application resumes normally. I spent quite some time trying to force a refresh of the background image unsuccessfully. (the repaint the image directly, repaint all children of a few panels, etc. ) Thus, I am looking for any tips that would help me resolve this problem under Mac OS X 10.4 or, in the worst case, simply simulate a full applet refresh.

Until recently, everything was compatible with Java 1.1 but this has changed in a few locations which now require 1.4. I don't feel these changes created the issue, I am just providing this as extra information. If you are interested in implementation details of the scroll panel, I will investigate, but I am assuming this is a common platform bug for which workarounds must be known.

To replicate the problem, open the following Java Web Start application:
http://www.lavablast.com/tmp/opal-webstart.php.jnlp

Select a folder containing lots of images and play with the scrollbar. At some point (fairly quickly), you should get the refresh problem.

Edit: I followed the first suggestion here and replaced all my controls that feature background images with a Swing equivalent and the issue is still there. (Plus, there are numerous other fixes I would need to do to do a complete change). Any other ideas? A simple one line of code that forces a full refresh would be great :)

Edit2: The main thread creates the panels and launches X threads. Using an observer/notifier pattern, the threads complete and notify the main control, which adds a panel to the page. This is done via an EventQueue.invokeLater which, unless I am mistaken, should run on the right thread. The issue is at its most severe when scrolling even if no extra threads are running (as during the loading).

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

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

发布评论

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

评论(2

長街聽風 2024-07-13 13:07:55

它看起来确实像是将轻量级(通常是 Swing)和重量级(AWT)组件混合在一起。 迁移到 Swing 后,您需要替换所有最后一个 AWT 组件 Swing 等效项(提示:避免 import java.awt.*)。

线程通常是奇怪错误的潜在问题。 Swing 组件必须始终在 EDT 上使用(使用 java.awt.EventQueue.invokeLater)。 AWT 理论上是线程安全的,但实际上并非如此 - 还限制对 EDT 的使用。

It does look like mixing lightweight (usually Swing) and heavyweight (AWT) components together. Moving to Swing you need to replace every last AWT component Swing equivalents (hint: avoid import java.awt.*).

Threading is often a potential problem for odd bugs. Swing components must always be used on the EDT (use java.awt.EventQueue.invokeLater). AWT is thread-safe is theory, but not in practice - also restrict usage to the EDT.

夜未央樱花落 2024-07-13 13:07:55

由于您已经需要 Java 1.4,您应该考虑进行一些小的更改以改用 SWING GUI,它解决了我们使用 AWT 的 Applet 刷新问题。 (Mac,Linux等)

如果你有例如Panel,你需要用JPanel等替换它。

你需要这个:

import javax.swing.*;

As you already require Java 1.4 you should consider some small changes to take into use SWING GUI instead, it solved our Applet refresh issues with AWT. (Mac, Linux etc)

If you have e.g. Panel, you need to replace it with JPanel etc.

You need this:

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