Is there some way to detect if a JTextField is deselected, i.e. the field WAS selected but now you have selected something else. The reason why I want to do this is because I want to check my users forms for any illegal characters before they try to submit their data. If there is some easier way to do that, instead of the way I'm trying to solve it, I'll gladly accept enlightenment.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
At first though use a
FocusAdapter
and overridefocusLost(FocusEvent fe)
which will be called whenJTextField
loses focuses, i.e another component is selected.However because you have a purpose:
Id suggest a read on How to Use the Focus Subsystem - Validating Input
Better options than a
FocusAdapter
- tailored made for validating/restricting user input:DocumentFilter
. See here and this variation for an example.InputVerifier
. See here for an exampleJFormattedTextField
. See here for an example