Java 小程序、AWT 刷新,在 Mac OS X 10.4 上发布 [英] Java Applet, AWT Refresh, issue on Mac OS X 10.4

查看:31
本文介绍了Java 小程序、AWT 刷新,在 Mac OS X 10.4 上发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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),我们的小程序在 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 下解决此问题的提示,或者在最坏的情况下,只需模拟一个完整的小程序刷新.

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.*).

线程通常是奇怪错误的潜在问题.Swing 组件必须始终在 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 小程序、AWT 刷新,在 Mac OS X 10.4 上发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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