I'm having some trouble with an InputVerifier on an input form I'm making.
What I want to happen:
What is actually happening is that the verifier fires, invalidates, message box, beep. User: crap, let me do some research first, clicks okay, clicks cancel, and the verifier fires again because clicking on the button causes focus to be lost. The only way to be able to cancel is to clear the bad entry so the verifier doesn't show as invalid. I can't even make a 'clear' button for precisely the same reasons.
One way to fix it, would be to clear the entry when it is invalid, but for usablility purposes, I prefer not to ruin the user's work because of a typo.
I've found so many ways that people recommend doing this kind of stuff but I'm not sure I picked the right way:
I'm trying to keep this implementation simple, but everytime I turn around, it seems I need to add another verifier, filter, listener or something.
Is there a best practices guide for building UI's and wiring stuff together (either a generic one or one focused on Java/Swing? GUI code (other than simply building the UI's) seems to confound me... <old procedural programmer - Pascal, C, ASM>
Any suggestions?
What I want to happen:
Code:
(1) User enters data in a field
(2) User hits 'tab' (or otherwise causes focus to be lost on that field)
(3) Validation routine hits
(a) if valid, continue
(b) if not valid
1. popup message box, wrap the user on the knuckles, tell them to get their act together
2. beep
3. when they close the message box, retain focus in the invalidated field
(4) If the user decides that they don't want to submit their entry, hit cancel and all is forgotten/forgiven
What is actually happening is that the verifier fires, invalidates, message box, beep. User: crap, let me do some research first, clicks okay, clicks cancel, and the verifier fires again because clicking on the button causes focus to be lost. The only way to be able to cancel is to clear the bad entry so the verifier doesn't show as invalid. I can't even make a 'clear' button for precisely the same reasons.
One way to fix it, would be to clear the entry when it is invalid, but for usablility purposes, I prefer not to ruin the user's work because of a typo.
I've found so many ways that people recommend doing this kind of stuff but I'm not sure I picked the right way:
Code:
(1) extend PlainDocument
(2) extend DocumentFilter
(3) extend InputVerifier
(4) create a FocusListener/extend FocusAdapter
(5) etc.
I'm trying to keep this implementation simple, but everytime I turn around, it seems I need to add another verifier, filter, listener or something.
Is there a best practices guide for building UI's and wiring stuff together (either a generic one or one focused on Java/Swing? GUI code (other than simply building the UI's) seems to confound me... <old procedural programmer - Pascal, C, ASM>
Any suggestions?