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);
来源:https://stackoverflow.com/questions/31708163/numberformat-text-field-without-commas