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

Removing Text from TextField / TextArea is not possible after typing

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 7u40, 8, 9
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b100
    • CPU:
      x86_64
    • OS:
      windows_7
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      Bug occurs on all java-versions from 1.7 onwards, for example:
      java version "1.7.0_65"
      Java(TM) SE Runtime Environment (build 1.7.0_65-b19)
      Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode, sharing)
      and
      java version "1.8.0_11"
      Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
      Java HotSpot(TM) Client VM (build 25.11-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Bug occurs on all Windows-versions (x86/x64), for example:
      Microsoft Windows XP [Version 5.1.2600]
      Microsoft Windows [Version 6.1.7601]
      Microsoft Windows [Version 6.2.9200]

      A DESCRIPTION OF THE PROBLEM :
      Since java-version 1.7 it is not possible to remove (clear/empty) text from the awt.TextField or awt.TextArea after the user has typed text in it. Calling the methods setText("") or setText( new String() ) or setText( null ) does not work as expected. If a java-program sets text in the TextComponent, removing the text by calling the method setText("") is possible. It seems that from java-version 1.7 onwards the awt.TextComponent does not recognize that a user has changed the text by typing on a keyboard.

      REGRESSION. Last worked in version 6u45

      ADDITIONAL REGRESSION INFORMATION:
      All java-versions until 1.7, for example:
      java version "1.6.0_03"
      Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
      Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.) Compile the example program with java 1.6, run it on Windows with java 1.6, 1.7 and 1.8.
      2.) Type some text in the TextField and the TextArea.
      3.) Press the button 'Remove'

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      With all java-versions on Windows the TextField and TextArea should be empty after pressing the Button 'Remove' which calls the method setText("") regardless of whether a user typed text in an awt.TextComponent or a java-program sets text in a TextComponent.
      ACTUAL -
      Beginning with java-version 1.7 (including 1.8) the awt.TextArea and the awt.TextField is not empty after the user typed text in that TextComponent and called the method setText("").

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;

      public class TextClearBug extends Frame
      {
        Label myLabel = new Label("Type something and press Remove");
        
        TextField myTextField = new TextField();
        TextArea myTextArea = new TextArea(1,30);
        Button myClearButton = new Button("Remove");
        
        public TextClearBug()
        {
      this.setLayout(new GridLayout(4, 1, 5, 5));

      this.add( myLabel );
      this.add( myTextField );
      this.add( myTextArea );
      this.add( myClearButton );


      myClearButton.addActionListener(new ActionListener()
      {
      public void actionPerformed(ActionEvent e)
      {
      String clearString = new String("");

      System.out.println("Set Text in TextField to <"+clearString+">");
      System.out.println("Set Text in TextArea to <"+clearString+">");

      myTextField.setText( clearString );
      myTextArea.setText( clearString );
              }
          });

         }

        public static void main(String[] args)
        {
      TextClearBug myTextClearBug = new TextClearBug();
      myTextClearBug.pack();
      myTextClearBug.setVisible( true );
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Just before calling setText(""), call getText(), or setText(" "):

      // clear Bugfix1
      myTextField.getText();
      myTextField.setText("");

      // clear Bugfix2
      myTextField.setText(" ");
      myTextField.setText("");

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                arapte Ambarish Rapte
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: