Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

InputVerifier clarification  RSS feed

 
Ken Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Any insight would be helpful.

Tested on Jdk1.3 & Jdk1.5, using Swing.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ken Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!