问题描述
我们有一个使用AWT构建的Java Applet.此小程序可让您从硬盘驱动器中选择图片并将其上传到服务器.该小程序包含一个可滚动的图片列表,在Windows,Linux和Mac OS X 10.5中可以正常使用.我们通过Java Web Start或在网页中启动此applet.
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.
无论Java的版本(1.4或1.5)如何,我们的applet在Mac OS X 10.4中均无法正常运行.滚动时,您可以在此处找到错误行为的屏幕截图:
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
简单地说,有时在滚动图片时最终会与应用程序的页眉或页脚重叠.在其他平台上不会发生此现象.在Mac OS X 10.4上,它在滚动时将图片显示在错误的位置,如果在该位置绘制图像后刷新屏幕,则效果不错.但是,似乎应用程序似乎不知道它绘制的不正确,因此不会刷新.
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.
如果将窗口最小化,调整大小甚至移动,则将刷新应用程序,并且错误放置的元素将消失,并且应用程序将正常恢复.我花了很多时间尝试不成功地刷新背景图像. (直接重新绘制图像,重新绘制几个面板的所有子对象,等等.)因此,我正在寻找可以帮助我在Mac OS X 10.4下解决此问题的任何技巧,或者在最坏的情况下,只需模拟一个完整的applet刷新.
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.
直到最近,所有内容都与Java 1.1兼容,但是在一些需要1.4的地方已经改变了.我认为这些更改不会引起问题,我只是提供此作为其他信息.如果您对滚动面板的实现细节感兴趣,我将进行调查,但是我假设这是一个常见的平台错误,必须知道其解决方法.
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.
要复制该问题,请打开以下Java Web Start应用程序: http://www.lavablast.com/tmp/opal-webstart.php. jnlp
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.
我遵循这里的第一个建议,并用等效的Swing替换了所有带有背景图像的控件,但问题仍然存在. (此外,我还需要做许多其他修复才能进行完整的更改).还有其他想法吗?一个简单的强制完全刷新的代码行会很棒:)
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:主线程创建面板并启动X线程.使用观察者/通知者模式,线程完成并通知主控件,该主控件将一个面板添加到页面.这是通过EventQueue.invokeLater完成的,除非我弄错了,否则应在正确的线程上运行.即使没有额外的线程正在运行(如在加载过程中),滚动时问题也最严重.
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).
推荐答案
它看起来确实像是将轻量级(通常是Swing)组件和重量级(AWT)组件混合在一起.转到Swing,您需要替换所有最后的AWT组件Swing等效项(提示:避免导入java.awt.*).
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.*).
线程通常是奇怪错误的潜在问题. EDT必须始终使用摆动组件(使用java.awt.EventQueue.invokeLater
). AWT是线程安全的,但从理论上讲不是安全的-还将使用限制在EDT中.
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.
这篇关于Java Applet,AWT Refresh,在Mac OS X 10.4上发行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!