NumberFormat text field without commas

10,787

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

Share:
10,787
2mac
Author by

2mac

Updated on July 03, 2022

Comments

  • 2mac
    2mac almost 2 years

    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?