This week's book giveaway is in the Game Development forum.
We're giving away four copies of Badass: Making Users Awesome and have Kathy Sierra on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Decimal Format is not setting the value in text field correctly. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Decimal Format is not setting the value in text field correctly." Watch "Decimal Format is not setting the value in text field correctly." New topic
Author

Decimal Format is not setting the value in text field correctly.

Chinmay Kant
Greenhorn

Joined: Feb 04, 2008
Posts: 20
I have a text field which will have only Integer (positive and negative values). So,I am using JFormattedtextField as shown below:-

The getFormatter(0 method is as follows:-

This makes me only type 0 to 9 and - sign iniside the text box.
My Problem:-
I have already a neagtive value like "-1222" inside the text field
[Now using if a set a value which is positive i.e "1234"
then after that i see the result as "-1234"
Here though my value was positive, it did not remove the negative sign
What could be the problem not getting???
Is my formatter wrong??



Thanks and Regards,
Chinmay
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19947
    
  24

Why not use a JSpinner with a SpinnerNumberModel?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
 
subject: Decimal Format is not setting the value in text field correctly.