I'm going through source code of large Swing
GUI application.
And I've noticed when they want to do something in case focusGained(Focus evn)
or focusLost(Focus evn)
they always use invokeLater()
.
Example:
yourTextField.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
yourTextField.selectAll();
}
});
}
});
Why invokeLater
is needed here?