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

requestFocus not working in 1.1.7

XMLWordPrintable

    • x86
    • windows_nt



      Name: tb29552 Date: 10/01/98


      /*
      Run the test code below, which works under 1.1.6 but
      not under 1.1.7.

      The intention of the code in the WindowOpened event is
      to try to find the current username by querying the
      system properties, automatically enter it into the
      userid textfield, and then setting focus to the
      password textfield. If no userid is found, focus
      should be set at the userid textfield.

      Under 1.1.6, the passwordTextField.requestFocus() call
      properly sets focus to the password textfield when a
      username is found. Under 1.1.7, the
      passwordTextField.requestFocus() method is called, but
      focus does not get set to the password TextField.

      Please advise about any workarounds or proper ways of
      accomplishing this in 1.1.7.

      Sample code:
      ------------
      */
      import java.awt.*;
      import java.awt.event.*;
      public class TestFrame extends Frame implements WindowListener {
          private Label PasswordLabel = new Label("Password:");
          private TextField PasswordTextField = new TextField();
          private Label UserIdLabel = new Label("UserId:");
          private TextField UserIdTextField = new TextField();

          public TestFrame () {
      super();
      setLayout(null);
      setSize(188, 116);

      UserIdTextField.setBounds(75, 33, 87, 27);
      this.add(UserIdTextField);

      PasswordTextField.setEchoChar('*');
      PasswordTextField.setBounds(75, 71, 87, 27);
      this.add(PasswordTextField);

      UserIdLabel.setBounds(7, 33, 59, 23);
      this.add(UserIdLabel);

      PasswordLabel.setBounds(7, 71, 65, 30);
      this.add(PasswordLabel);

      this.addWindowListener(this);

          }

          public static void main(java.lang.String[] args) {
      //TestFrame aTestFrame = new sandbox.focusbug.TestFrame ();
      TestFrame aTestFrame = new TestFrame ();
      aTestFrame.setVisible(true);
          }

          public void windowActivated(java.awt.event.WindowEvent e) {
          }

          public void windowClosed(java.awt.event.WindowEvent e) {
          }

          public void windowClosing(java.awt.event.WindowEvent e) {
      this.dispose();
      System.exit(0);
          }

          public void windowDeactivated(java.awt.event.WindowEvent e) {
          }


          public void windowDeiconified(java.awt.event.WindowEvent e) {
          }


          public void windowIconified(java.awt.event.WindowEvent e) {
          }


          public void windowOpened(java.awt.event.WindowEvent e) {
      UserIdTextField.setText(System.getProperty("user.name"));
      if (UserIdTextField.getText().trim().length() > 0)
      PasswordTextField.requestFocus();
      else
      UserIdTextField.requestFocus();
          }

      }

      (Review ID: 39802)
      ======================================================================

            rkhansunw Robi Khan (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: