Results 1 to 2 of 2
  1. #1
    javaw is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Question JFormattedTextField and MaskFormatter

    Hi,

    Hoping a Swing guru on here might shed a little light on a problem I have.

    I've got little or no time to get a solution for this into a clients application and so far... well, I'm losing lots of hair - so any help on this would be gratefully appreciated!!!

    Basically, all I need to do is permit the user to enter an amount of money into a text field. However, it needs to be formatted on the fly so that:

    If they press 1, the output appears as 0.01
    If they then press 2, the output appears as 0.12
    If they then press 3, the output appears as 1.23
    and so on.

    The idea is that it automatically determines where the decimal point is - without the user having to enter it themselves.

    The formatter has to permit only numeric characters and support the deletion of characters.

    I've tried all sorts of solutions:

    MaskFormatter - starts entering the characters from left to right - no good.
    DefaultFormatterFactory - doesn't format the field until focus changes or enter pressed
    KeyListener - can detect a new keypress but can't change the text from within the event without it appearing twice
    I've even tried messing around with the Caret, but to no avail.

    Help!

    This should be a simple thing to do, but Swing is baffling me on this one

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. add jformattedTextfield in jtable
    By anilkumar_vist in forum Advanced Java
    Replies: 1
    Last Post: 11-18-2009, 06:42 PM
  2. JFormattedTextField / Formatter / OverWriteMode
    By Ralphw in forum AWT / Swing
    Replies: 1
    Last Post: 08-20-2009, 12:23 PM
  3. JFormattedTextField + SimpleDateFormat
    By Ralphw in forum AWT / Swing
    Replies: 1
    Last Post: 07-07-2009, 11:53 AM
  4. Problems with JFormattedTextField
    By Gatts79 in forum New To Java
    Replies: 0
    Last Post: 10-03-2008, 05:59 PM
  5. JFormattedTextField Issue
    By teracomp in forum AWT / Swing
    Replies: 1
    Last Post: 01-21-2008, 07:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •