Reputation: 1446
I have the following code:
JOptionPane.showMessageDialog(this, "Wrong format!", "Wrong format!", JOptionPane.ERROR_MESSAGE);
myJTextField.requestFocusInWindow();
The JTextField does not get focus after execution of JOptionPane, how do I fix this in a nice and clean way? My JTextField is on a JTabbedPane.
Upvotes: 0
Views: 461
Reputation: 12670
showMessageDialog
blocks the EDT until you have confirmed the dialog. So the line of code you have setting the focus won't run until after the dialog is gone.
Upvotes: 0
Reputation: 109815
this isn't easy job move Focus
betweens two Top-Level Containers
, because Focus came from native OS and is asynchronous,
you have to delay this event to the invokeLater()
, if without success then you have to look for Dialog Focus by @camickr
Upvotes: 3