I have created a JFormattedTextField using a NumberFormatter as the format. I can enter values and it keeps me from going too high or low and always entering numeric data. The problem I have is once I enter data, I can't just backspace over all of it. It always makes me leave one digit in the field. I can highlite the digit and type in new data, but I can't make the field completely blank. Is there a way for me to do this?
Here's the scenario.
I start with a field to enter a year which is currently blank.
I enter '2000' but then I decide I want the field to be blank again.
I backspace 4 times to delete the four characters. The three 0's are deleted but the field will not let me delete the '2'. It just beeps at me.
If I enter an additional character and then move the caret over to the '2' and then press backspace I can delete it, but I still have something in the field and I want the field totally blank.
I also cannot highlite the data and press the delete key to get rid of it. It won't allow that either.
I meet the same problem, but have unfortunately no solution. However, I read that there is at least one bug in JFormattedTextField
Although its description has nothing to do with our case but cuts the last character instead, maybe there are still unobserved side effects.
I realize this is an old post, but I think the solution is in the formatter.
call getFormatter() of your JFormattedTextField.
on the formatter you get set the allowsInvalid property to true.
I think this should solve your problem.