JTextField "unselect" event detection

Is there a way to determine if the JTextField is being canceled, i.e. the WAS field is selected, but now you have selected something else. The reason I want to do this is because I want to check my user forms for any illegal characters before they try to submit their data. If there is some simpler way to do this, instead of trying to solve it, I gladly accept enlightenment.

+3
source share
1 answer

First use the FocusAdapter and override the focusLost(FocusEvent fe) , which is called when the JTextField loses focus, i.e. another component.

However, since you have a goal:

I want to check my user forms for any illegal characters before they try to submit their data

Id suggests reading How to use the focus subsystem - confirmation of input

More effective options than FocusAdapter - specially designed to check / limit user input:

+10
source

All Articles