简体   繁体   English

Java Applet,AWT Refresh,在Mac OS X 10.4上发行

[英]Java Applet, AWT Refresh, issue on Mac OS X 10.4

We have a Java Applet built using AWT. 我们有一个使用AWT构建的Java Applet。 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. 该小程序包含一个可滚动的图片列表,在Windows,Linux和Mac OS X 10.5中可以正常使用。 We launch this applet via Java Web Start or within a web page. 我们通过Java Web Start或在网页中启动此applet。

Our applet does not behave properly in Mac OS X 10.4, regardless of the version of Java (1.4 or 1.5). 不管Java的版本(1.4或1.5)如何,我们的applet在Mac OS X 10.4中均无法正常运行。 You can find a screenshot of the incorrect behaviour, when scrolling, here: 滚动时,您可以在此处找到错误行为的屏幕截图:

http://www.lavablast.com/tmp/ui_error.png 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. 在Mac OS X 10.4上,它在滚动时将图片显示在错误的位置,如果在该位置绘制完图像后刷新屏幕,效果还不错。 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. (直接重新绘制图像,重新绘制几个面板的所有子对象,等等。)因此,我正在寻找可以帮助我在Mac OS X 10.4下解决此问题的任何技巧,或者在最坏的情况下,只需模拟一个完整的applet刷新。

Until recently, everything was compatible with Java 1.1 but this has changed in a few locations which now require 1.4. 直到最近,所有内容都与Java 1.1兼容,但这在某些需要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 要复制该问题,请打开以下Java Web Start应用程序: 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. 编辑:我遵循这里的第一个建议,并用等效的Swing替换了所有带有背景图像的控件,但问题仍然存在。 (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. Edit2:主线程创建面板并启动X线程。 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. 这是通过EventQueue.invokeLater完成的,除非我弄错了,否则应在正确的线程上运行。 The issue is at its most severe when scrolling even if no extra threads are running (as during the loading). 即使没有额外的线程正在运行(如在加载过程中),滚动时问题也最严重。

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. 由于您已经需要Java 1.4,因此应该考虑使用SWING GUI进行一些小的更改,它解决了AWT的Applet刷新问题。 (Mac, Linux etc) (Mac,Linux等)

If you have eg Panel, you need to replace it with JPanel etc. 如果您有例如Panel,则需要用JPanel等替换它。

You need this: 你需要这个:

import javax.swing.*;

It does look like mixing lightweight (usually Swing) and heavyweight (AWT) components together. 看起来确实像将轻量级(通常是Swing)和重量级(AWT)组件混合在一起。 Moving to Swing you need to replace every last AWT component Swing equivalents (hint: avoid import java.awt.*). 转到Swing,您需要替换所有最后的AWT组件Swing等效项(提示:避免导入java.awt。*)。

Threading is often a potential problem for odd bugs. 线程化通常是奇数个bug的潜在问题。 Swing components must always be used on the EDT (use java.awt.EventQueue.invokeLater ). Swing组件必须始终在EDT上使用(使用java.awt.EventQueue.invokeLater )。 AWT is thread-safe is theory, but not in practice - also restrict usage to the EDT. AWT从理论上讲是线程安全的,但实际上却不是-还将使用限制为EDT。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM