I've linked a new InputVerifier (DateVerifier.java) to a JTextField, but its not acting as I would expect, but only on the FIRST time the text field is dealt with. Here's the scenario:
We have an application that has a field on it which holds a birthdate. We've done an InputVerifier to check for a valid date, and do some other checks specific to birth dates. If an invalid date is entered, the shouldYeildFocus method will pop up a JOptionPane to complain about the error. It will also return false for the method.
The first time the VM is started up, and the application is executed, if an operator enters an invalid date, ie. "abc," and clicks the "save" button (without tabbing away), the JOptionPane does pop up, but the action associated with the save button still happens.
I thought the InputVerifier.shouldYieldFocus method would stop the focus from being transferred to the "save" button, and thus stop the save action from happening.
I would recommend that you not override the shouldYieldFocus method; let java call this on its own. Try putting your code in the verify method.
In this test app use the tab key to move in and out of the verified JTextField.
posted 15 years ago
We originally had the login in the .verify, but I found some documentation that said the .verify should not "stop" anything - i.e., no pop-ups, etc. Anyway, I found bug report #4302322 having to do with InputVerifier, FocusLost, and JButtons. Basically, clicking on a JButton causes different focus actions to occur than tabbing away from a field.