Subclass InputVerifier : Document Event « Swing JFC « Java






Subclass InputVerifier

    

 
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JTextField;

public class Main {

  public static void main(String[] args) {
    JTextField tf = new JTextField("");
    tf.setInputVerifier(new MyInputVerifier());

  }
}

class MyInputVerifier extends InputVerifier {
  public boolean verify(JComponent input) {
    JTextField tf = (JTextField) input;
    String pass = tf.getText();
    return pass.equals("AA");
  }
}

   
    
    
    
  








Related examples in the same category

1.DocumentFilter that maps lowercase letters to uppercaseDocumentFilter that maps lowercase letters to uppercase
2.An extension of PlainDocument that restricts the length of its contentAn extension of PlainDocument that restricts the length of its content
3.Document Event DemoDocument Event Demo
4.React to the document update insert changed eventReact to the document update insert changed event
5.HTMLDocument: Document Iterator Example
6.DocumentListener DemoDocumentListener Demo
7.extends PlainDocument to create a float value type text field
8.extends PlainDocument to create alpha and numeric value based field field
9.Implement a document cleaner that maps lowercase letters to uppercaseImplement a document cleaner that maps lowercase letters to uppercase
10.Document ElementIterator DemoDocument ElementIterator Demo
11.Format JTextField's text to uppercase
12.Overriding a Few Default Typed Key Bindings in a JTextComponent
13.Overriding - key
14.Override $ key
15.Overriding space key
16.Disable a character so that no action is invoked.
17.Bind a keystroke to shift-space
18.Prevent the space from being inserted when shift-space is pressed.
19.extends PlainDocument
20.This Document restricts the size of the contained plain text to the given number of characters.
21.A frame with three text fields to set the background color.