Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NumberFormat text field without commas

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?

like image 911
2mac Avatar asked Jul 29 '15 18:07

2mac


1 Answers

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

like image 145
bobbel Avatar answered Sep 19 '22 06:09

bobbel