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

If AWT TextArea gains focus via TAB, it doesn't display next key press

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.2_012
    • 1.2.2_009
    • client-libs
    • 012
    • sparc
    • solaris_8



      Name: kb87695 Date: 09/26/2001


      Sep'01 Kevin_brown@sun wrote:
      This bugs is ONLY found in JDK 1.2.2 Reference releases. It is not
      found in JDK 1.2.1 production and 1.2.2 production. I have verified this bug
      in all reference ports up to JDK 1.2.2_009.

      This bug is also not found in JDK 1.3.

      HP would like a fix for Solaris Reference 1.2.2._00next



      //Program Name TnoScroll.java
      // Sun BUG: How to Duplicate the Problem:
      //
      //Problem:HP chart defect number JAGad76398
      //If AWT TextArea gains focus via TAB, it does not display the key
      //pressed. Upon a mouseEntered, it will correctly display the key.
      //This is broken in Solaris JDK 1.2.2_009
      //and is fixed in the prelim build of JDK 1.2.2._010
      //It is fixed in Solaris 1.3.
      //
      //To duplicate, use TnoScroll.java;
      //1. The application screen has text fields and text area
      //2. Some text is typed in the TextArea on the right.
      //3. Click on the textfield to the left of the textarea (That has the text) and press "Tab" key
      //so that the focus comes on the textarea and the text written in
      //the textarea is selected but mouse-cursor is still on the
      //textfield.
      //4. Press any key -- it will not display (eg. Press
      //"Delete" and it does not delete the selected characters.
      //5. Bring the mouse-cursor anywhere in the textarea and then press
      //"Delete/Backspace" key. It works.

      import java.awt.*;
      import java.awt.event.*;
      import java.awt.event.InputEvent.*;

      public class TnoScroll extends Frame implements MouseListener,
      KeyListener,FocusListener {


           private Label description;

           private String descriptionStr = "Current Password",
                             descriptionStr2 = "New Password ",
                             descriptionStr3 = "Comments";
           private TextField l_tfUserList;
           private TextField l_tfpwdList;
           private TextArea l_ta;
           private Panel buttonPanel;
           private Button okBtn, cancelBtn;

           private String okBtnStr = " OK ",
                               cancelBtnStr = "Cancel";

           static final String newline = "\n";

           public TnoScroll() {

                this.setLayout(new FlowLayout());
                setFont(new Font("serif",Font.PLAIN,12));

                description = new Label(descriptionStr);
                this.add(description);
                l_tfUserList = new TextField("",30);
                //l_tfUserList.setBackground(java.awt.Color.white);
                this.add(l_tfUserList);

                description = new Label(descriptionStr2);
                this.add(description);
                l_tfpwdList = new TextField("",30);
                //l_tfpwdList.setBackground(java.awt.Color.white);
                this.add(l_tfpwdList);
                l_tfpwdList.setEchoChar('*');

                description = new Label(descriptionStr3);
                this.add(description);

                l_ta= new TextArea("TextArea99",9,9,TextArea.SCROLLBARS_NONE);
      // l_ta.setBackground(java.awt.Color.white);
                this.add(l_ta);

               okBtn = new Button(okBtnStr);
               this.add(okBtn);

               cancelBtn = new Button(cancelBtnStr);
               this.add(cancelBtn);

                l_tfUserList.addMouseListener(this);
                l_tfpwdList.addMouseListener(this);
                l_ta.addMouseListener(this);
                l_tfUserList.addKeyListener(this);
                l_tfpwdList.addKeyListener(this);
                l_ta.addKeyListener(this);
                l_ta.addFocusListener(this);
                l_tfUserList.addFocusListener(this);
                l_tfpwdList.addFocusListener(this);

                addWindowListener(new WindowAdapter() {
                     public void windowClosing(WindowEvent we) {
                          dispose();
                          System.exit(0);
                     }
                });

                setSize(450,330);
                setBackground(SystemColor.control);
           }
                public void mousePressed(MouseEvent e){
                System.out.println("mousePressed is called");
                }
                public void mouseEntered(MouseEvent e){
                System.out.println("mouseEntered is called");
                }
                public void mouseExited(MouseEvent e){
                System.out.println("mouseExited is called");
                }
                public void mouseClicked(MouseEvent e){
                System.out.println("mouseClicked is called");
                }
                public void mouseReleased(MouseEvent e){
                     System.out.println("mouseReleased is called");
                }
                public void focusGained(FocusEvent evtFocus)
                {
                          System.out.println("focus gained is called");
                     TextComponent txcText = (TextComponent)evtFocus.getSource
      ();
                     txcText.select(0,3);

                }
                public void focusLost(FocusEvent evtFocus){
                     System.out.println("inside focus lost");
                     TextComponent txcText = (TextComponent)evtFocus.getSource
      ();
                     int nPos = txcText.getCaretPosition();
                     txcText.select(nPos, nPos);
                     txcText.setCaretPosition(1);
                }

                public void keyPressed(KeyEvent r_keEvent)
                {
                     System.out.println("Inside keyPressed"+getFocusOwner());
                     displayInfo(r_keEvent, "KEY PRESSED: ");
                }
                public void keyReleased(java.awt.event.KeyEvent r_keEvent){
                     System.out.println("Inside keyReleased");
                     displayInfo(r_keEvent, "KEY RELEASED: ");
                }
                public void keyTyped(java.awt.event.KeyEvent r_keEvent){
                     System.out.println("Inside keyTyped");
                     displayInfo(r_keEvent, "KEY TYPED: ");
                }


              protected void displayInfo(KeyEvent e, String s){
              String charString, keyCodeString, modString, tmpString;

              char c = e.getKeyChar();
              int keyCode = e.getKeyCode();
              int modifiers = e.getModifiers();

              if (Character.isISOControl(c)) {
                  charString = "key character = "
                             + "(an unprintable control character)";
              } else {
                  charString = "key character = '"
                             + c + "'";
              }

              keyCodeString = "key code = " + keyCode
                              + " ("
                              + KeyEvent.getKeyText(keyCode)
                              + ")";

              modString = "modifiers = " + modifiers;
              tmpString = KeyEvent.getKeyModifiersText(modifiers);
              if (tmpString.length() > 0) {
                  modString += " (" + tmpString + ")";
              } else {
                  modString += " (no modifiers)";
              }

              System.out.print(s + newline
                                 + " " + charString + newline
                                 + " " + keyCodeString + newline
                                 + " " + modString + newline);
          }
           public static void main(String args[]) {
                String TitleStr = "Change Password";
                TnoScroll chps = new TnoScroll();
                chps.setVisible(true);
                chps.setTitle(TitleStr);
           }
      }

      ###@###.### 2001-09-26


      ###@###.### 2001-09-26

      (Review ID: 132583)
      ======================================================================

            prssunw Prs Prs (Inactive)
            kevibrow Kevin Brown
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: