• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JFormattedTextField entering data without special chars

 
Ranch Hand
Posts: 167
Netbeans IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I am tinkering with JFormattedTextField.
I have a test case which does Rates, Dollars, and Dates
They display the Data as desired.
However, when it comes to entering the data, it seems to require I enter the special chars for it to accept my input this is not desired.  When I google it, I get lots of posts on how to format how it looks but found nothing on the topic of modifying how you enter data.

I have data already entered at startup.
Edit any of the fields and clear the field
then enter just the numbers
for instance for the rate enter .2 and hit enter.
it does not accept it

or in the Dollar field
Type only 100.00
again, does not accept it.  

its like you must type in $100.00 for it to accept it.  Which is not what I want.

Hopefully someone here has delt with this and can point me in the right direction.

 
Sheriff
Posts: 28385
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess that's what the NumberFormat.getCurrencyInstance() method gives you. Although I have to say, the API documentation for NumberFormat doesn't give you examples which would tell you that.

If you just want to format decimal numbers with a fixed number of decimal places then DecimalFormat is what you want. Although if you need your code to work in many countries, some of which don't have decimal places in their currency, you will have some extra work.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

for instance for the rate enter .2 and hit enter.



Seems to work in the Swing tutorial on How to Use Formatted Text Fields.

Formatting is done when focus leaves the field.
 
Michelle Nicholes
Ranch Hand
Posts: 167
Netbeans IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You statement is incorrect for what I asked.  The demo in the link you provided is not displaying the percentage with the percent symbol and allowing you to enter without the symbol as I stated in my question.  So no, its not working as I asked.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, my mistake, I understand the issue now.

As a workaround, add a FocusListner to the text field and manually add the special character when focus is lost.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic