重点关注JDK7和本机组件的问题 [英] Focus problems with JDK7 and native components

查看:165
本文介绍了重点关注JDK7和本机组件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个swing应用程序,它通过JNIWrapper嵌入IE ocx组件。

We have a swing application which embeds a IE ocx component via JNIWrapper.

从jdk6切换到jdk7后,我们开始注意焦点问题。当嵌入式IE显示带有文本字段的网页(例如谷歌搜索页面)而不是麻烦开始时:

After switching from jdk6 to jdk7 we start noticing focus problems. When the embedded IE shows a web page with text fields (e.g. the google search page) than the trouble starts:

浏览器抓住焦点,所以你可以开始在搜索文本字段中输入。键入的每个键都进入IE ocx。但是,摆动似乎忽略了这种焦点变化。即使我将焦点更改为swing文本字段(并且swing显示闪烁的输入光标),所有键入的键都会转到IE ocx

The Browser 'catches' the focus, so u can start typing in the search text field. Every key typed goes to the IE ocx. But swing seems to ignore this focus change. Even if i change the focus to a swing text field (and swing shows the blinking input cursor), all typed keys goes to the IE ocx

修复的唯一方法'重点是取消激活和激活主框架。之后,焦点似乎是一致的。但是,如果我再次点击谷歌搜索文本字段,焦点会再次被打破。

The only way to 'fix' the focus is to deacitvate and activate the main frame. after that the focus seems to be consistent. But if i click in the google search text field again, the focus is broken again.

似乎jdk7中的焦点处理有很大的变化。来自链接

It seems there is a big change to focus handling in jdk7. From the link:


在Windows平台上,已经实现了合成焦点的概念。这意味着焦点所有者组件仅模拟其可聚焦状态,而实际本机焦点设置为焦点代理组件。此组件接收键和输入方法本机消息,并将它们分派给焦点所有者。在JDK7之前,焦点代理组件是框架/对话框内的专用隐藏子组件。在JDK7中,框架/对话框本身用作焦点代理。现在,它代理不仅关注拥有窗口中的组件,还关注所有子组件。一个简单的窗口永远不会接收本机焦点,并依赖于其所有者的焦点代理。这种机制对于用户来说是透明的,但在调试时应该考虑到这一点。

On the Windows platform, a concept of "synthetic focus" has been implemented. It means that a focus owner component only emulates its focusable state whereas real native focus is set to a "focus proxy" component. This component receives key and input method native messages and dispatches them to a focus owner. Prior to JDK7 a focus proxy component was a dedicated hidden child component inside a frame/dialog. In JDK7 a frame/dialog itself serves as a focus proxy. Now it proxies focus not only for components in an owned window but for all child components as well. A simple window never receives native focus and relies on focus proxy of its owner. This mechanism is transparent for a user but should be taken into account when debugging.

任何人都有想法修复这种行为?

Anyone has an idea to 'fix' the behavior?

编辑:这里有一些代码用 JxBrowser

EDIT: Here some code to reproduce the problem with JxBrowser

    public static void main(String[] args) {
    Browser browser = BrowserFactory.createBrowser(BrowserType.IE);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(browser.getComponent(), BorderLayout.CENTER);

    JPanel panel = new JPanel();
    frame.getContentPane().add(panel, BorderLayout.NORTH);

    textField = new JTextField();
    panel.add(textField);
    textField.setColumns(10);
    frame.setSize(700, 500);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    browser.navigate("http://www.google.com");
}


推荐答案

全部 - 我们刚刚经历过这个另一个浏览器组件(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
特别是关于sythentic焦点和焦点代理的部分。

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.

这篇关于重点关注JDK7和本机组件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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