We have a swing application that embeds the ocx IE component through JNIWrapper.
After moving from jdk6 to jdk7, we begin to notice focus problems. When embedded IE shows a web page with text fields (like a Google search page), than the problem starts:
The browser "captures" the focus, so you can start typing in the search field. Each key entered is sent to IE ocx. But swing seems to ignore this change of focus. Even if I focus on the swing text field (and the swing shows a blinking input cursor), all the keys entered go to IE ocx
The only way to “fix” the focus is to deactivate and activate the main frame. after that, the focus seems consistent. But if I click again in the Google search text box, the focus will break again.
It seems that in jdk7 there is a big shift in focus. From the link :
On the Windows platform, the concept of "synthetic focus" is implemented. This means that the focus owner component only emulates its custom state, while the real focus is set to the focus proxy component. This component receives the main and initial input method messages and sends them to the focus owner. Prior to JDK7, the focus proxy component was a dedicated hidden child component within the frame / dialog. In JDK7, the frame / dialog itself serves as the proxy focus. Now it proxies focuses not only on components in its own window, but also on all child components. A simple window never gets its own focus and relies on the focus proxy of its owner. This mechanism is transparent to the user, but it should be considered when debugging.
Does anyone have an idea to "fix" behavior?
EDIT: here is the 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"); }
source share