There is a problem in my application when trying to set focus on a JEditorPane using the tab key. I did not understand why at first, but I manage to make a small test case that demonstrates the issue.
public class JEditorPaneFocusTest
{
public static void main(String... args) throws Exception
{
JFrame jFrame = new JFrame();
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container container = jFrame.getContentPane();
container.setLayout(new BorderLayout());
container.add(new JTextField(), BorderLayout.NORTH);
JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new HTMLEditorKit());
editorPane.setText("<html><body>Hello World</body></html>");
container.add(editorPane, BorderLayout.CENTER);
jFrame.setSize(new Dimension(400, 400));
jFrame.setVisible(true);
}
}
(Tested on Windows 7 and Mac OS X Lion.) The application will start with focus on the JTextField. Using the tab key won’t set focus to the JEditorPane. But if you comment the setText line, it seems to work…
Any idea?
delay this event by wraping to the
invokeLater()Focus / Focus Subsystem is asynchronous, in most cases hard to manage/timing this/these even(s), for better understanding about this issue you have to read linked tutorials,
example about Focus issue