1

I have people entering a lot of currency amounts in form, so pressing one key less is important.

I would like to avoid pressing the decimal separator when entering currency ammount. I need a subclass of JTextField that will automatically show decimal and thousand separators while entering number. Is out there something already developed for instant use?

james.garriss
  • 12,255
  • 6
  • 78
  • 95
ante.sabo
  • 3,053
  • 6
  • 27
  • 36

2 Answers2

1

You can use a JFormattedTextField http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html,

Jeff Storey
  • 54,892
  • 71
  • 228
  • 402
  • yes... still no option for MaskFormatter to be hardcoded into text input area so user can't change it, only see it and browse around like it is JLabel, for instance.. – ante.sabo Feb 15 '10 at 14:17
  • You could override the setFormatter method so it doesn't actually change anything (after you set it once), or you could create a wrapper around JTextField that delegates all of its method calls to the underlying JTextField but doesn't have a setter method. – Jeff Storey Feb 15 '10 at 14:54
1

You can set an InputVerifier that can enforce any rules you want. This example shows a simple currency format and a data/time verifier that accepts multiple formats. You can adapt it to accept the default format and interpret a missing decimal separator as a value in cents.

Community
  • 1
  • 1
trashgod
  • 200,320
  • 28
  • 229
  • 974