Search code examples
javaswingvalidationjtextfield

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?


Solution

  • 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.