I have a problem in my application with focus handling. I am using a glass pane to prevent the user from interact with data while a lengthy process is running. So far, so good. However, if the process fails, I would like to display a warning dialog via JOptionPane.showMessageDialog.
My problem is, that the "Ok" button in the dialog is not focused. Pressing TAB works, but quite strangely: the button is focused, and if I reproduce the situation, the next time it is focused. Then it is not on the next time, etc.
Here is the code that sets the glass pane:
Initial settings for the glass pane:
How I use it before the long process runs:
The long process shows the message roughly like this:
It seems that the problem is the line getGlassPane().requestFocusInWindow(); But I have to give it the focus, so that the user cannot use the keys to meddle with the data when he should not.
How can I solve this problem?
Thanks, David [ May 03, 2007: Message edited by: David Nemeskey ]
posted 9 years ago
This is just a wild guess, but have you tried not specifying a parent component (using null) for the JOptionPane? Change your call to look like this:
Life is good on the Ponderosa,<br />but mind where you step.
The City calls upon her steadfast protectors. Now for a tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads