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.)
Public Methods
- public abstract boolean verify(JComponent input)
Return
trueif the component should give up focus, orfalseto 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
trueif the component should give up focus, orfalseto keep focus. This method is permitted to produce side effects.InputVerifier’s implementation simply defers to theverify( )method, but implementing classes may override either. Typically, subclasses provide only averify( )method unless they intend to produce side effects.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access