Need custom JTextField for currency
I have people entering a lot of currency amou开发者_如何学Cnts 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?
You can use a JFormattedTextField http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html,
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.
精彩评论