Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set a mask for JFormattedTextFields for currency?

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Unfortunately, this doesn't allow me to set a mask for the currency value.
I'd like to have, say with the RMB value, the user is not allowed
to type over the RMB symbol.
Thanks
Jack
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are two quite easy choices,

1. JPanel with JLabel andJFormattedTextField, remove Borders from JFormattedTextField and (before removed from JFormattedTextField) add put the same Borders to JPanel (JPanel.setBorder(JFormattedTextField.getBorder()))

2. serch for NavigationFilter, (there must be an post(s) about by Rob Camickr), then there you can to specify a number of columns in JTextField that aren't accesible for Mouse or KeyEvents, you would need to override Caret possition, setDot() and moveDot()
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m Korbel wrote:there are two quite easy choices,

1. JPanel with JLabel andJFormattedTextField, remove Borders from JFormattedTextField and (before removed from JFormattedTextField) add put the same Borders to JPanel (JPanel.setBorder(JFormattedTextField.getBorder()))

2. serch for NavigationFilter, (there must be an post(s) about by Rob Camickr), then there you can to specify a number of columns in JTextField that aren't accesible for Mouse or KeyEvents, you would need to override Caret possition, setDot() and moveDot()


Thanks, I will look into those options
Have fun
Jack
 
Brian Cole
Author
Ranch Hand
Posts: 912
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Luk wrote:I'd like to have, say with the RMB value, the user is not allowed
to type over the RMB symbol.


The way a currency JFormattedTextField usually works is it allows the user to type over the currency symbol, but the currency symbol will re-appear as soon as the field loses focus.

Here is one-way to change the currency symbol from ¥ to RMB¥:

If you really want to prevent the currency symbol from being temporarily deleted, it's possible but it's more work.
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, what a great idea...
Thanks
Jack
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic