Making JTextField accept mixed String , whet documentFIlter alow only digits
<p>I have unusual issue something is working a bit to well. I have written a <code>DocumentFilter</code> witch allow user input only as numbers, <code>DocumentFilter</code> add dash on it's own in proper place during writing. This way in<code>JTextField</code>  is visible  date like this is: "2016-05-01". The problem is that <code>JTextField</code>   is not always filled in by user, sometimes it must be set by program. But when I use code setText("2016-05-01"), it don't display properly, all dash are gone. How to make it work ? 
I tried to  change <code>DocumentFilter</code> to allow dash, but this why cause problems in many other places. I probably will end up writting another <code>DocumentFilter</code> just for this but maybe there is a other way? Is it possible to append <code>JTextField</code>    char by char ? Is there a way to switch on an off the  <code>DocumentFilter</code>, or mayby it's posible to change smartly <code>DocumentFilter</code> so it will not crush in oder palces and work here as well? Below part of code  for <code>DocumentFilter</code></p>

<pre><code>  public void replace(FilterBypass fb, int offs, int length, String str,
    AttributeSet a) throws BadLocationException {

if (str == null || str.equals(""))
{
    super.replace(fb, offs, length, str, a); 
}
else
{
    StringBuffer buffer = new StringBuffer(str);
    for (int i = buffer.length() - 1; i &gt;= 0; i--)
    {
    char ch = buffer.charAt(i);
    if (!Character.isDigit(ch))
    {
        buffer.deleteCharAt(i);
    }
    }

    str = buffer.toString();
    //sign and sign2 is char number were separator(sep) is written 
    if (fb.getDocument().getLength() + str.length() == sign)
    {
    str = str + sep;
    }
    if (fb.getDocument().getLength() + str.length() == sign2)
    {
    str = str + sep;
    }


    if ((fb.getDocument().getLength() + str.length() - length) &lt;= maxCharacters)
    super.replace(fb, offs, length, str, a);
    else
    Toolkit.getDefaultToolkit().beep();
}
</code></pre>