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

TextField.setEchoChar functions improperly

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.4
    • client-libs
    • sparc
    • solaris_2.5.1



      Name: diC59631 Date: 11/13/97


      After a TextField object setEchoChar to '*', setText
      displays the string itself not the echo characters.
      The echo character displays only when the user is
      typing in the TextField. Program calling setText
      will cause the TextField to display the text not
      the echo characters.

      The following code will defeat the setEchoChar method in
      the TextField class:
              import java.awt.*;
              import java.awt.event.*;
              import java.applet.*;

              public class PasswordTest extends Applet implements
      ActionListener {

                      public void actionPerformed(ActionEvent e)
                      {
                              String lab = ((MenuItem)e.getSource()).getLabel();
                              if (lab.equals("Test"))
                              {
                                      tester.tfPassword.setText("This is a test");
                              }
                              else
                             if(lab.equals("Exit"))
                             {
                                   System.exit(0);
                             }
                      }
                      PasswordTest()
                      {
                      }
                      TextField tfPassword;
                      Font font;
                      static PasswordTest tester;
                      MenuBar mb;
                      public void init()
                      {
                              setLayout(null);
                              font = new Font("Dialog", Font.PLAIN, 12);
                              tfPassword = new TextField("",50);
                              tfPassword.setFont(font);
                              tfPassword.setEchoChar('*');
                              add(tfPassword);
                              tfPassword.setBounds(10, 10, 150, 30);
                              Menu m = new Menu("File");

                              MenuItem mi1 = new MenuItem("Test");
                              mi1.addActionListener(this);
                              m.add(mi1);

                              MenuShortcut ms3 = new MenuShortcut(KeyEvent.VK_E);
                              MenuItem mi3 = new MenuItem("Exit", ms3);
                              mi3.addActionListener(this);
                              m.add(mi3);

                              mb = new MenuBar();
                              mb.add(m);
                      }

                      public static void main(String args[])
                      {
                              Frame f = new Frame("testing");
                              tester = new PasswordTest();
                              f.add(tester);
                              tester.init();


                              f.setMenuBar(tester.mb);
                              f.setSize(200, 200);
                              f.setVisible(true);
                      }

              }
      I compiled this piece code on Sun Netra I5 machine which
      has Solaris operating system. Then I ran this code, in the
      File menu I selected Test, the plain text "This is a test"
      shown in the tfPassword. Based on the code, the echo
      characters "**************" should show in the tfPassword
      field. The same piece of code runs fine on NT 4.0 and
      Windows 95. This is the simplest piece of code that can
      demonstrate the problem.


      (Review ID: 19208)
      ======================================================================

            lbunnisunw Lara Bunni (Inactive)
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: