title: How to disallow characters in JFormattedTextField?
body: <p>In NetBeans, how can I setup invalid characters for <code>JFormattedTextField</code> so that it does not allow: <code>|</code>, <code>[</code>, <code>]</code> and etc.?</p>
  
  <p><strong>Never mind, I figured out the solution:</strong></p>
  
  <pre><code>MaskFormatter formatter = null;
  
          try {
              //# - Any valid number, uses Character.isDigit.
              //' - Escape character, used to escape any of the special formatting characters.
              //U - Any character (Character.isLetter). All lowercase letters are mapped to upper case.
              //L - Any character (Character.isLetter). All upper case letters are mapped to lower case.
              //A - Any character or number (Character.isLetter or Character.isDigit)
              //? - Any character (Character.isLetter).
              //* - Anything.
              //H - Any hex character (0-9, a-f or A-F).
              formatter = new MaskFormatter("******************************");
              formatter.setInvalidCharacters("|[]");
          } catch (java.text.ParseException ex) {
          }
  </code></pre>
  
  <p>then, on the GUI right click on the JFormattedTextField, click on Customize Code, for the dropdown box beside <code>myFormattedTextField = new javax.swing.JFormattedTextField();</code> select custom creation and add formatter to JFormattedTextField as following: <code>myFormattedTextField = new javax.swing.JFormattedTextField(formatter);</code></p>
  
  <p>Hope this will help somebody else one day.</p>