A Java applet has the following in its start() method :
this.setFocusable(true);
this.requestFocus();
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.
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.
解决方案
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?
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.