Java 小程序在 JRE 1.6.0_29 及更高版本(OS X)中没有获得焦点 [英] java applet not grabbing focus in JRE 1.6.0_29 and up (OS X)

查看:25
本文介绍了Java 小程序在 JRE 1.6.0_29 及更高版本(OS X)中没有获得焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 小程序在其 start() 方法中具有以下内容:

A Java applet has the following in its start() method :

this.setFocusable(true);
this.requestFocus();

启动时,小程序仅在某些 OS/JRE/浏览器配置中获取焦点.它是使用 JDK 1.6.0_18 编译的,在我运行 Java 1.7 的 PC 上,它可以毫无问题地在所有浏览器(即 chrome、Firefox)中获得焦点;即使小程序是使用 JDK 1.7 编译的.

When launched, the applet grabs the focus only in certain OS/JRE/browser configurations. It's compiled using JDK 1.6.0_18, and on my PC running Java 1.7 it grabs focus in all browsers (Ie, chrome, Firefox) without problems; even if the applet is compiled using JDK 1.7.

在 Java 1.6.0_29 附带的 Mac OS X 10.6.8 上,它不会在 Safari、Chrome 或 Firefox 中获取焦点,但小程序加载正常.当我将 Mac OSX JDK 升级到预览版 1.7 时 - 它根本不加载小程序.如果我使用 JDK 1.7 编译小程序并使用 JRE 1.7 运行 - 它只会使 Mac 上的浏览​​器崩溃.

On Mac OS X 10.6.8 which comes with Java 1.6.0_29 it doesn't grab focus in Safari, Chrome or Firefox, but the applet loads fine. When I upgrade the the Mac OSX JDK to the preview 1.7 - it doesnt' load the applet at all. If I compile the applet using JDK 1.7 and run using JRE 1.7 - it just crashes the browsers on the Mac.

有没有人遇到过类似的问题?谢谢.

Has anyone come across similar problems? thanks.

推荐答案

文档.对于 组件.requestFocus() 状态:

The docs. for Component.requestFocus() state:

由于此方法的焦点行为是平台相关的,因此强烈建议开发人员使用 requestFocusInWindow 可能的话.

Because the focus behavior of this method is platform-dependent, developers are strongly encouraged to use requestFocusInWindow when possible.

在这种情况下可以使用后者吗?

Is it possible to use the latter in this case?

有没有人遇到过类似的问题?

Has anyone come across similar problems?

焦点问题与嵌入式小程序密切相关.如果您想要更可靠的焦点行为,请使用 Java Web Start 启动小程序自由浮动.

Focus problems go hand-in-hand with embedded applets. If you want more reliable focus behavior, launch the applet free-floating using Java Web Start.

这篇关于Java 小程序在 JRE 1.6.0_29 及更高版本(OS X)中没有获得焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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