I have class that extends FocusAdapter, i have ovenriden the focusLost method to be the following:
public void focusLost(FocusEvent e)
{
JTextField textField = (JTextField) e.getSource();
String content = textField.getText();
if (content.length() != 0)
{
try
{
Float.parseFloat(content);
}
catch (NumberFormatException nfe)
{
Toolkit.getDefaultToolkit().beep();
textField.requestFocus();
textField.selectAll();
}
}
}
As the catch block shows i want to beep, set focus back to the field that had the error and select the text.
My problem is focus will not return to the field, it does the beep and it selects the text but focus does not return, what am I doing wrong?
Is they another way I can do the valadiation?
Robert