Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

InputVerifier clarification

 
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.
 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic