I have a JFormattedTextField which I want to accept numbers in the 5 digit range. The following code works correctly:
myNumberBox = new JFormattedTextField(NumberFormat.getIntegerInstance());
However, when I type "12345" into the field and switch focus, a comma is inserted due to my locale, making the text "12,345". How can I prevent commas from being added to my input? Better yet, can they be stripped out even if the user does insert commas?
You have to disable the grouping in your NumberFormat object like this:
NumberFormat format = NumberFormat.getIntegerInstance();
format.setGroupingUsed(false);
myNumberBox = new JFormattedTextField(format);
See: NumberFormat.setGroupingUsed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With