且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JDK7 和原生组件的焦点问题

更新时间:2022-01-10 17:30:18

所有 - 我们刚刚在另一个浏览器组件(DjProject Native Swing)中遇到了这个问题.在 Java 1.6 下一切正常,但在 Java-7 下,我们开始看到奇怪的问题,您可以在输入框中输入内容,但如果您向后选择以修复错字,则在单击鼠标后无法输入.要恢复,您必须从输入字段中选择,然后再返回以继续编辑.

All - We just experienced this problem with another browser component (DjProject Native Swing). Everything works fine under Java 1.6 but under Java-7 we started seeing weird problems where you can type into an input box but if you select backwards to fix a typo you could not type after making the mouse click. To recover you had to select out of the input field and then back in to continue your edit.

参见 http:///docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/awt.html#gdcqp特别是这里关于合成焦点和焦点代理的部分.

See http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/awt.html#gdcqp Particularly the part here about sythentic focus and focus proxies.

总之长话短说 - 在我们的例子中,我能够通过将鼠标侦听器附加到 JWebBrowser.getNativeComponent() 来找到解决方法.然后在 mousePressed 上执行 browser.requestFocus() 后跟 browser.getNativeComponent().requestFocusInWindow();

Anyway to cut a long story short - in our case I was able to find a work-around by attaching a mouse listener to the JWebBrowser.getNativeComponent(). Then on mousePressed execute a browser.requestFocus() followed by a browser.getNativeComponent().requestFocusInWindow();

希望这对遇到此问题的其他人有所帮助.

Hope this helps anyone else that comes across this.