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

Non-editable JFormattedTextField allows date changes with cursor keys.

XMLWordPrintable

    • b74
    • x86
    • windows_xp

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The JFormattedTextField allows the key cursors to modify a date value when the editable property is set to false. When the field has focus the the up and down cursor keys allow the user to change the value for the selected field.

      JFormattedTextField use of the editable property is inconsistent with the JTextField. The JFormattedTextField uses the editable property like a JComboBox.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JFormattedTextField using a SimpleDateFormat. Call setValue using a vaild date object and set the editable property to false. When the field is displayed use the mouse or keyboard to change focus to the JFormattedTextField. While the field has focus press the cursor up or cursor down to change (spin) the selected date field. The mouse can be used to select specific parts of the date to allow the cursor key to spin different fields in the date.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected the value to remain the same.

      Setting the editable property to false should block all user changes to the current value. Since the JFormattedTextField is JTextField setting the editable property on either should have the same result.
      ACTUAL -
      The date can be modified by the user.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.text.SimpleDateFormat;
      import java.util.Date;

      public class DateTest extends JFrame implements Runnable {
        public DateTest() {
        }
        
        public void run() {
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          JFormattedTextField field =
              new JFormattedTextField(new SimpleDateFormat("MM/dd/yyyy"));
          field.setValue(new Date());
          field.setEditable(false);
          this.add(field);
          this.setSize(200,200);
          this.validate();
          this.setVisible(true);
        }

        public static void main(String[] args) {
          SwingUtilities.invokeLater(new DateTest());
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      1. Set the enabled property to false and change the disabled text color.
      2. Override processKeyEvent to ignore key events if disabled.
      ###@###.### 2005-04-26 13:44:17 GMT

            alexp Alexander Potochkin (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: