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

Escape key cancels text entered into JFormattedTextField.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.4.1
    • client-libs



      Name: rmT116609 Date: 03/04/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      If you hit the Escape key after typing into a JFormattedTextField, the text you typed will be replaced by the previous contents of the field.
      This is inconsistent with the behavior of JTextField. Since the Escape key has nothing to do with formatting, they should behave the same way.
      If the JFormattedTextField does not have any formatting applied to it, this behavior doesn't occur.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Add a JFormattedTextField to a panel.
      2. Apply some form of formatting to the field.
      3. Display the panel.
      4. Type a value into the field that matches the format.
      5. Put focus somewhere else on the screen.
      6. Return focus to the field.
      7. Replace the text with something different
      8. With focus still in the field, hit the Esc key.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Nothing should happen. The new text that I type in should still be there.
      The new text that I typed in disappeared and the text in the field reverted to what was in it previously.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.text.*;
      import javax.swing.*;

      /**
       * Shows how pressing the Escape key from a textfield with formatting causes
       * the text to revert to the previous value. This behavior is inconsistent with
       * non-formatted textfields, which don't do anything when Escape is pressed.
       */
      public class TestTFEsc extends JDialog {
      public static void main(String[] args) {
      new TestTFEsc();
      }

      public TestTFEsc() {
      super();
      getContentPane().setLayout(new GridLayout(2, 2));

      JLabel lblNonFormatted = new JLabel("Non-formatted:");
      getContentPane().add(lblNonFormatted);

      // Create a non-formatted textfield
      JTextField tfNonFormatted = new JTextField(10);
      getContentPane().add(tfNonFormatted);

      JLabel lblFormatted = new JLabel("Formatted (integers):");
      getContentPane().add(lblFormatted);

      // Create a formatted textfield (integers only).
      // It must have some sort of formatting to display the behavior,
      // otherwise it acts like a normal textfield.
      JFormattedTextField tfFormatted = new JFormattedTextField(
      NumberFormat.getIntegerInstance());
      tfFormatted.setColumns(10);
      getContentPane().add(tfFormatted);

      pack();
      setModal(true);
      setVisible(true);
      System.exit(0);
      }
      }
      ---------- END SOURCE ----------
      (Review ID: 182083)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: