Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024066

JFormattedTextField with MaskFormatter reports its value as null on loosing focus

    XMLWordPrintable

Details

    Description

      We setup JFormattedTextField as follows:

      MaskFormatter formatter = new MaskFormatter("##-##-##");
      JFormattedTextField fmtFld1 = new JFormattedTextField(formatter);
      fmtFld1.addFocusListener(focusListener);

      Then we correctly fill fmtFld1 with some value such as 11-11-11

      Then we press Tab key so the field looses focus.

      When it looses focus focusListener.focusLost() gets called. In it we are acquiring the field's value with fmtFld1.getValue().

      However it reports null, and not the correct value.

      If we call getValue() ourselves some time before that then null is no more reported.

      This behaviour does not happen with other formatters, but with MaskFormatter only.

      The attached program demonstrates the issue. To see the issue run the program, type 11-11-11 in the first field and press tab. In the console there will be printed null and not 11-11-11


      Attachments

        Activity

          People

            Unassigned Unassigned
            akulyakh Alexander Kulyakhtin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: