20.10 The InputVerifier Class
InputVerifier is an abstract class introduced in SDK
1.3. Subclasses of InputVerifier can be attached
to JComponents to control whether they are willing
to give up focus. Typically, this is done to force the user to put a
component in a "valid" state before
allowing the user to transfer focus to another component.
A brief example of using an InputVerifier with a
JFormattedTextField appeared earlier in this
chapter. (See the focusLostBehavior property of
the JFormattedTextField class.)
20.10.1 Public Methods
- public abstract boolean verify(JComponent input)
-
Return true if the component should give up focus,
or false to keep focus. You should implement this
method to examine the component and make the determination, but you
should not produce any side effects on the component.
- public boolean shouldYieldFocus(JComponent input)
-
This method is called when the user attempts to transfer focus from
the given component elsewhere. Return true if the
component should give up focus, or false to keep
focus. This method is permitted to produce side effects.
InputVerifier's implementation
simply defers to the verify( ) method, but
implementing classes may override either. Typically, subclasses
provide only a verify( ) method unless they intend
to produce side effects.
|