Results 1 to 1 of 1
- 10-03-2008, 05:59 PM #1Member
- Join Date
- Aug 2008
- Rep Power
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...
- By raj4u in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 02-07-2008, 11:06 AM
- By teracomp in forum AWT / SwingReplies: 1Last Post: 01-21-2008, 07:55 PM
- By saytri in forum New To JavaReplies: 1Last Post: 12-16-2007, 11:27 PM
- By cecily in forum JDBCReplies: 1Last Post: 08-02-2007, 06:51 PM
- By gary in forum AWT / SwingReplies: 0Last Post: 07-11-2007, 05:57 PM