Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2008, 05:59 PM
Member
 
Join Date: Aug 2008
Posts: 16
Rep Power: 0
Gatts79 is on a distinguished road
Default Problems with JFormattedTextField
Hell Everyone-

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.

1st Way:
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.

2nd Way:
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);
floatField.setValue(new Float("1.0"));

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...

Gatts79
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems in JSP : Need help raj4u JavaServer Pages (JSP) and JSTL 1 02-07-2008 11:06 AM
JFormattedTextField Issue teracomp AWT / Swing 1 01-21-2008 07:55 PM
GUI problems. saytri New To Java 1 12-16-2007 11:27 PM
many to many problems cecily Database 1 08-02-2007 06:51 PM
a few problems gary AWT / Swing 0 07-11-2007 05:57 PM


All times are GMT +2. The time now is 07:18 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org