File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes NumberFormat, Currency, JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "NumberFormat, Currency, JTextField" Watch "NumberFormat, Currency, JTextField" New topic

NumberFormat, Currency, JTextField

Thomas Mcfarrow
Ranch Hand

Joined: Jul 09, 2001
Posts: 137

I want to make a JTextField that will take input in and format it accordingly to the current locale's currency. The key here is that programmatically I need to detect what locales have decimal points.

Additionally, I need the number input to start from the right.

Furthermore, I have a somewhat working model for US currency but I would like to make it generic enough for global use.

For example (US Dollar):

User Enters 2 --> JTextField shows $0.02
User Enters 3 --> JTextField shows $0.23
User Enters 4 --> JTextField shows $2.34
User Enters 5 --> JTextField shows $23.45
User Enters 6 --> JTextField shows $234.56

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
See the class DecimalFormatSymbols. You might also want to take a look at JFormattedTextField.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: NumberFormat, Currency, JTextField
jQuery in Action, 3rd edition