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

JTextField does not fire PropertyChangedEvent when Text property changes

XMLWordPrintable

    • tiger
    • x86
    • linux



      Name: jk109818 Date: 10/24/2002


      FULL PRODUCT VERSION :
      [alex@meat alex]$ java -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 OPERATING SYSTEM VERSION :

      [alex@meat alex]$ rpm -query glibc
      glibc-2.2.4-30
      [alex@meat alex]$ uname -a
      Linux meat 2.4.7-10 #1 Thu Sep 6 16:46:36 EDT 2001 i686 unknown
      )
      [alex@meat alex]$ cat /etc/*release
      Red Hat Linux release 7.2 (Enigma)

      ADDITIONAL OPERATING SYSTEMS :

      All

      A DESCRIPTION OF THE PROBLEM :
      A JavaBean should fire a PropertyChange event when any of
      its properties change.

      JTextField has a property named "text", as signified by its
      getText and setText methods.

      When a client of JTextField calls its setText() method, the
      text is changed, but the PropertyChange event is not fired.

      The Swing source code demonstrates that JTextField delegates
      its text to the document; however, it really should conform
      to the standard for JavaBeans. Developers can waste time
      needlessly looking for the workaround, and it also means
      that using JTextFields in JavaBean-aware builders will not
      function properly.





      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see source code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      expected: print property change event
      actual: nothing happens

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.beans.*;

      public class TextFieldBug {
          public static void main(String[] args)
          {
              JTextField text = new JTextField();
              text.addPropertyChangeListener(new PropertyChangeListener()
              {
                  public void propertyChange(PropertyChangeEvent evt)
                  {
                      System.out.println("Received Event=" + evt);
                  }
              });
              text.setText("something");
          }
      }

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

      CUSTOMER WORKAROUND :
      Use the textField's document's DocumentListener instead:

              textField.getDocument().addDocumentListener(new
      DocumentListener() {
                  public void insertUpdate(DocumentEvent e) {
                      update();
                  }

                  public void removeUpdate(DocumentEvent e) {
                      update();
                  }

                  public void changedUpdate(DocumentEvent e) {
                      update();
                  }
              });
      (Review ID: 166214)
      ======================================================================

            peterz Peter Zhelezniakov
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: