4 Replies Latest reply: Oct 9, 2004 2:49 AM by 807587 RSS

    Deleting last number in JFormattedTextField.

    807577
      I have created a JFormattedTextField using a NumberFormatter as the format. I can enter values and it keeps me from going too high or low and always entering numeric data. The problem I have is once I enter data, I can't just backspace over all of it. It always makes me leave one digit in the field. I can highlite the digit and type in new data, but I can't make the field completely blank. Is there a way for me to do this?

      Thanks
        • 1. Re: Deleting last number in JFormattedTextField.
          807577
          Don't understand the question much, but from what I think I get, try JFormattedTextField.trim().
          • 2. Re: Deleting last number in JFormattedTextField.
            807577
            Here's the scenario.

            I start with a field to enter a year which is currently blank.

            I enter '2000' but then I decide I want the field to be blank again.

            I backspace 4 times to delete the four characters. The three 0's are deleted but the field will not let me delete the '2'. It just beeps at me.

            If I enter an additional character and then move the caret over to the '2' and then press backspace I can delete it, but I still have something in the field and I want the field totally blank.

            I also cannot highlite the data and press the delete key to get rid of it. It won't allow that either.
            • 3. Re: Deleting last number in JFormattedTextField.
              807577
              I meet the same problem, but have unfortunately no solution. However, I read that there is at least one bug in JFormattedTextField
              http://developer.java.sun.com/developer/bugParade/bugs/4832257.html
              Although its description has nothing to do with our case but cuts the last character instead, maybe there are still unobserved side effects.

              J�rg
              • 4. Re: Deleting last number in JFormattedTextField.
                807587
                I realize this is an old post, but I think the solution is in the formatter.

                call getFormatter() of your JFormattedTextField.
                on the formatter you get set the allowsInvalid property to true.

                I think this should solve your problem.