Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTextField validation

I wrote my own InputVerifier for JTextField and it works fine. Now I would like to "force" validation on this text field when user clicks a button. Is it possible to do?

like image 251
Jarek Mazur Avatar asked Jul 24 '26 09:07

Jarek Mazur


1 Answers

Added as answer as @JarekMazur said it solved the problem.

Re-iterating my comment:

+1 @MadProgrammer for the docs

See this similar question/answer. It shows use how to programmatically trigger JTextField enter key pressed using Robot class and requestFocusInWindow(), though I think you would only need the latter.

Try changing JTextField focus using requestFocusInWindow().

You would initially request focus on the JTextField and than to another component in order to fire the Input Verifier shouldYieldFocus method.

like image 56
David Kroukamp Avatar answered Jul 25 '26 22:07

David Kroukamp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!