🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #11691

Re: JTextField validation

#11691
From: Max Polk
Date: Mon, 19 Apr 1999 00:00
25 lines
1929 bytes
In article <7fg4uv$suv26@forums.borland.com>, david.gnemi@agencyworks.com 
says...
> I am trying to validate JTextFields - min/max age, etc.  I would like to
> check the input in the field and not let the user move out of the textField
> until the input is valid.  I can do this when the return key is hit and
> validate on the actionPerformed event, but when I try to validate on the
> FocusLost event - and try to redirect the focus 'back' to the field the
> focus gets screwed up.

If you get a focus lost event, note that you *ALREADY* lost focus.  Focus 
is *GONE*.  Another component *ALREADY* has the focus.  To move focus 
back, the new component gets a focus lost event.  Will you then validate 
the new component as well losing focus back to the original?

See how complicated all this is?  I personally highly advise *AGAINST* 
doing things on a focus lost.  One good way to do validation is on each 
keystroke by writing your own Document.  It's quite easy.

If a long-running process needs to occur on each validation, and you 
don't want that each keystroke, then wait one second after the last 
keystroke is pressed, and do validation then.  Enable the "Next" or "Ok" 
button or whatever to prevent continuing on the *FIRST* keystroke after 
validation passes.  As long as the user is typing, no validation occurs.  
When they stop for a full second, validation occurs.  If validation 
succeeds, only then enable the "Next" or "Ok" or whatever.
Technical Details
Message-ID: <MPG.1185a5346cbef1cf9896d7@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7fg4uv$suv26@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,816558d5accb6dda
X-Google-Attributes: gid111d45,public
From: none@none.invalid (Max Polk)
Subject: Re: JTextField validation
Date: 1999/04/19
Message-ID: <MPG.1185a5346cbef1cf9896d7@forums.borland.com>
X-Deja-AN: 468540541
References: <7fg4uv$suv26@forums.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing