title: How to make textfield have 2 document filters
body: <p>I have a code here that i got form MDP's weblog. the sizefilter and the number filter. how do i make a textfield set its filter for two document filters. </p>
  
  <p>Here isthe numberfilter</p>
  
  <pre><code>import javax.swing.text.BadLocationException;
  import javax.swing.text.AttributeSet;
  import javax.swing.text.DocumentFilter;
  
  public class IntFilter extends DocumentFilter {
  
  public void insertString(DocumentFilter.FilterBypass fb, int offset,
                           String string, AttributeSet attr)
          throws BadLocationException {
  
      StringBuffer buffer = new StringBuffer(string);
      for (int i = buffer.length() - 1; i &gt;= 0; i--) {
          char ch = buffer.charAt(i);
          if (!Character.isDigit(ch)) {
              buffer.deleteCharAt(i);
          }
      }
      super.insertString(fb, offset, buffer.toString(), attr);
  }
  
  public void replace(DocumentFilter.FilterBypass fb,
                      int offset, int length, String string, AttributeSet attr) throws BadLocationException {
      if (length &gt; 0) fb.remove(offset, length);
      insertString(fb, offset, string, attr);
  }
  }
  </code></pre>
  
  <p>this code is for the sizefilter</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.text.AttributeSet;
  import javax.swing.text.BadLocationException;
  import javax.swing.text.DocumentFilter;
  
  public class SizeFilter extends DocumentFilter {
  
  private int maxCharacters;    
  
  public SizeFilter(int maxChars) {
      maxCharacters = maxChars;
  }
  
  public void insertString(FilterBypass fb, int offs, String str, AttributeSet a)
          throws BadLocationException {
  
      if ((fb.getDocument().getLength() + str.length()) &lt;= maxCharacters)
          super.insertString(fb, offs, str, a);
      else
          Toolkit.getDefaultToolkit().beep();
  }
  
  public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a)
          throws BadLocationException {
  
      if ((fb.getDocument().getLength() + str.length()
              - length) &lt;= maxCharacters)
          super.replace(fb, offs, length, str, a);
      else
          Toolkit.getDefaultToolkit().beep();
  }
  }
  </code></pre>