title: How to use a filter for textfields in java swing?
body: <p>I have a <code>JTextField</code>. And when the user enters <code>a</code> or <code>j</code>, I want the text within the text field to be upper-case (e.g. enter "ab", output "AB"). And if the first letter is not one of the following,</p>
  
  <ul>
  <li><code>a</code>, <code>t</code>,<code>j</code>, <code>q</code>, <code>k</code>, <code>2</code>, <code>3</code>, ...,<code>9</code> </li>
  </ul>
  
  <p>I don't want the text field to display anything. </p>
  
  <p>And here's what I have,</p>
  
  <pre><code>public class Gui {
      JTextField tf;
      public Gui(){
          tf = new JTextField();
          tf.addKeyListener(new KeyListener(){
             public void keyTyped(KeyEvent e) {
             }
             /** Handle the key-pressed event from the text field. */
             public void keyPressed(KeyEvent e) {
             }
             /** Handle the key-released event from the text field. */
             public void keyReleased(KeyEvent e) {
             }
          });
      }
  }
  </code></pre>