Problems with JFormattedTextField
I've been playing around with the JFormattedTextField trying to get it to accept only Float values and displaying it in the format of ###.######### . I have read several differnt tutorials over this and have gotten very mixed results.
JFormattedTextField floatField = new JFormattedTextField(new Float("1.000"));
Stepping through the debugger the value in floatField says it is Float and the value there shows up as 1.0. According the the java docs when the field losses focus or enter is pressed commitEdit is automatically called and that should update the floatField's value. I edit the field with 2.38999 and press enter while debugging. I check floatField's value says 1 but now instead of being a Float it is listed as Long; this is completely opposite of what is stated in the tutorials and java docs.
DecimalFormat format = new DecimalFormat("###.#########");
format.setMaximumIntegerDigits(3); // cap 3 spots before decimal
format.setMinimumFractionDigits(9); // cap 9 spots after decimal
format.setDecimalSeparatorAlwaysShown(true); // always see the decimal
NumberFormatter formatter = new NumberFormatter(format;
JFormattedTextField floatField = new JFormattedTextField(formatter);
From what I understand; the code snippet above specifies the JFormattedTextField to format the field as a decimal with a maximum of 3 integer fields and minimum of 9 fractional fields. By default the minimum integer fields is 1 and the minimum fractional fields is 1. Running it through the debugger without setting a value the default value is 1.0 and it is of type Float. I change the field to 2.339999 and press enter and looking through the debugger the value is set as 2 and it is a Long. I look at the formatter for the JFormattedTextField and it is everything that I specified when I created it. It seems as if it ignored all the format specifications I set.
Anyone have any ideas? Thanks in advance guys...