I used JFormattedTextField
withNumberFormat
in this way:
-Creat a JFormattedTextField
refernce
JFormattedTextField integerField;
-Create a NumberFormat
refernce
NumberFormat integerFieldFormatter;
-In the constructor:
integerFieldFormatter = NumberFormat.getIntegerInstance();
integerFieldFormatter.setMaximumFractionDigits(0);
integerField = new JFormattedTextField(integerFieldFormatter );
integerField.setColumns(5);
..........
I meant to use it with integer numbers only, but when I type numbers like 1500 it is converted after losing focus to 1,500 , and exception thrown this is the first line of it:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "1,500"
When I use JTextField
instead of JFormattedTextField
All integers accepted normally, But the reason why I want to use JFormattedTextField
is to benefit from its input restriction advantages.