NumberFormat text field without commas

大城市里の小女人 提交于 2019-12-18 15:54:33

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/31708163/numberformat-text-field-without-commas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!