I need such a numeric text field on JFrame that
- restricts the input by a number with two digits after decimal point
- lays out the number separating every three digits i.e. 1 234 567,89.
- the number is displayed in correct format right away during typing
I tried using JFormattedTextField:
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
NumberFormatter numFormater = new NumberFormatter(nf);
field1 = new javax.swing.JFormattedTextField(numFormater);
However, format restricitions apply only when focus leaves the component, which is a problem. I want user to be able to type only digits and delimeter in the field, and a space delimeter be placed right after each 3-d digit is entered in the field.
I can do this in C# just by specifing properties of the field. What is a clean way to do this in Swing? Thank you.