将鼠标事件处理从 Java 1.5 更改为 1.6

发布于 2024-10-06 22:01:36 字数 1172 浏览 0 评论 0原文

我们最近将我们的一个(编辑)Linux java 应用程序从 java 1.5 迁移到了 java 1.6,并且由于两个版本之间 MouseEvent 发送的变化而受到了很大的影响,这让我们的应用程序在几天内非常不高兴,直到我们追踪到了它。

简而言之,当用户右键单击最终派生自 awt.Canvas 的类以调出 JPopupMenu 时,在 Java 1.5 中,原始画布会收到鼠标右键向上事件,但在 Java 1.6 中我们永远不会听到鼠标向上事件。这会让我们的应用程序陷入混乱,因为它维护着内部鼠标按钮映射,并进入不一致的状态。

(编辑)这适用于 Linux - 在 Windows 上,我们在 java 1.5 和 1.6 上都会收到鼠标向上事件。

我编写了一个简短的程序,它创建一个画布并在其上附加一个弹出菜单,通过单击鼠标右键触发,并将事件记录到控制台。如果我在 java 1.5 下编译并运行它,然后左键单击,然后右键单击,我会看到以下内容:

EventCanvas->mousePressed mb: [L..]
EventCanvas->已发布 mb:[...]
EventCanvas->mouseClicked mb: [...]
EventCanvas->mousePressed mb: [..R]
EventCanvas->Released mb: [...]

但如果我在 java 1.6 下执行相同操作,我会看到:

EventCanvas->mousePressed mb: [L..]
EventCanvas->已发布 mb:[...]
EventCanvas->mouseClicked mb: [...]
EventCanvas->mousePressed mb: [..R]

我的问题是:这是众所周知的吗?有据可查吗?对于这种情况有标准的解决方法吗?

我们现在又拥有了一个运行良好的程序,所以这个问题只是出于好奇 - 但我很惊讶地看到版本之间出现这样的变化。顺便说一句 - 如果有人想告诉我保留鼠标状态的内部映射有点奇怪,也许是这样,但我们在这里讨论的是大型 GUI 密集型遗留应用程序,大规模重写并不总是一种选择。

示例代码可见:http://teapot7.com/sample.html

We recently moved one of our (edit) Linux java applications from java 1.5 to java 1.6 and got bitten quite hard by what seems to be a change in MouseEvent sending between the two versions, which left our application very unhappy for a few days until we tracked it down.

In short, when the user right clicks on a class ultimately derived from awt.Canvas to bring up a JPopupMenu, in Java 1.5 the originating canvas receives the right mouse up event, but in Java 1.6 we never hear the mouse up event. This sends our application into a tizzy, as it's maintaining an internal mouse button map, and gets into an inconsistent state.

(edit) This only applies to Linux - on Windows we receive mouse up event on both java 1.5 and 1.6.

I've written a short program which creates a canvas and attaches a popup menu to it, triggered by right mouse click, and logs the events to the console. If I compile and run this under java 1.5 and do a left click then a right click, I see the following:

EventCanvas->mousePressed mb: [L..]
EventCanvas->Released mb: [...]
EventCanvas->mouseClicked mb: [...]
EventCanvas->mousePressed mb: [..R]
EventCanvas->Released mb: [...]

but if I do the same under java 1.6 I see:

EventCanvas->mousePressed mb: [L..]
EventCanvas->Released mb: [...]
EventCanvas->mouseClicked mb: [...]
EventCanvas->mousePressed mb: [..R]

My question, such as it is: Is this well known? Well documented? Are there standard workarounds for this sort of situation?

We have a happily operational program again now, so this question is just out of curiosity - but I was surprised to see a change like this between versions. BTW - if someone wants to tell me it's a bit odd to be keeping an internal map of mouse state, perhaps so, but we're talking a large gui intensive legacy application here, and a large scale rewrite isn't always an option.

The sample code can be seen at: http://teapot7.com/sample.html

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

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

发布评论

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

评论(1

转身泪倾城 2024-10-13 22:01:36

我的问题是:这是众所周知的吗?有据可查吗?

目前还不完全清楚你的问题是什么(参见@RD的评论),所以我不能说这个。

一般来说,已知会对应用程序产生影响的更改记录在相应的“JDK 采用指南”文档中。在 JDK 6 文档中,AWT 部分列出了更改应用程序可能看到的事件的各种修复。 (在“事件触发的变化”标题下。)其中之一看起来可能描述了您所看到的内容。

可能记录此类更改的其他位置是发行说明(其中列出了每个次要版本中的所有已修复错误)和错误数据库。

这是否算“有据可查”由你来判断。但我认为确实如此。

对于这种情况有标准的解决方法吗?

一般来说,没有......除了回滚到旧的 JVM 直到找到修复程序为止。

对于“Swing / AWT 中的某些内容发生了变化”的“标准解决方法”是什么?

My question, such as it is: Is this well known? Well documented?

It is not entirely clear what your problem is (see @RD's comment), so I cannot say for this one.

In general, changes that are known to impact on applications are documented in the respective "JDK Adoption Guide" documents. In the JDK 6 document, the AWT section lists various fixes that have changed the events that applications may see. (Under the heading "Changes in event firing".) One of them looks like it might describe what you are seeing.

Other places where changes like this might be documented are in the Release Notes (which list all fixed bugs in each minor release) and the Bug Database.

Whether this counts as "well documented" is for you to judge. But I reckon it does.

Are there standard workarounds for this sort of situation?

In general, no ... apart from rolling back to the older JVM until you can find a fix.

What would a "standard workaround" for "something has changed in Swing / AWT" be?

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