title: Creating A JTextField Input Validator
body: <p>I am trying to create a <code>JTextField</code> input validator following <a href="http://www.javalobby.org/java/forums/t20551.html" rel="nofollow">Building a Swing Validation Package with InputVerifier</a>. I have taken all the class on that page an am now trying to use the <code>NotEmptyValidator</code> found <a href="http://www.javalobby.org/java/forums/t20552.html" rel="nofollow">here</a>. I have a <code>JFrame</code> and a <code>JTextField</code>. I am trying to use this package but its giving me an error.The code is shown below:</p>
  
  <pre><code>public class ValidateTest extends JFrame {
  public JTextField field;
  
  public ValidateTest() {
      this.field = new JTextField();
      this.field.setInputVerifier(new NotEmptyValidator(this, this.field,
              "No Empty Value"));// The line showing an error.
  
      this.setTitle("ValidateTest");
      this.setVisible(true);
      this.setSize(200, 200);
      this.setLayout(new BorderLayout());
      this.add(this.field, BorderLayout.NORTH);
  }
  
  public static void main(String[] args) {
  
      try {
          for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
                  UIManager.setLookAndFeel(info.getClassName());
                  break;
              }
          }
      } catch (Exception e) {
  
      }
      ValidateTest vt = new ValidateTest();
     }
   }
  </code></pre>
  
  <p><strong>NOTE:</strong> I have just taken the classes as they are. The only code I have added is above.</p>
  
  <p><strong>My Questions:</strong>
  1. How do I instantiate the <code>NotEmptyValidator</code>? I mean I provided the <code>JTextField</code>and the <code>String</code> but don't know how to do it with the <code>JDialog</code>.</p>
  
  <ol start="2">
  <li>How do we resolve this error and what went wrong here?</li>
  </ol>