Because your regular expression doesn't allow for it. Your regular expression matches Strings that start with a digit 1-9, followed by up to four more digits, then optionally a period and up to two more digits. (I'm curious why, say, 0.5
isn't legal for you, but that's a separate question.)
The empty string (what you have after deleting the 1
in your example) doesn't match this regex, and so the JFormattedTextField
won't allow it.
When you initially construct the JFormattedTextField
you never try to match it on its initial empty value, so it's allowed then. But when the user starts typing, you run the match on all the values subsequently entered, including (if applicable) the empty string when all characters are deleted.
You could try changing if (string == null) return null;
to if (string == null || string.trim().equals("")) return null;
... this would allow a blank field.