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

awt: requestFocus not working while moving away from proc. using ALT-TAB in jdk 5.0 upd 14

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • 5.0u14
    • 5.0u14
    • client-libs
    • x86
    • windows_xp

      RequestFocus is not working while move away from process using ALT+TAB in JDK 1.5.0-14.
      This is not reproduceable with 1.4.2_16.

      Testcase:

       Here is testcase to reproduce the problem :
       
      _________________________________________________________________
        
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.FocusAdapter;
      import java.awt.event.FocusEvent;
      import java.awt.event.KeyAdapter;
      import java.awt.event.KeyEvent;
      import javax.swing.JButton;
      import javax.swing.JTextField;
      import javax.swing.JFrame;
      import javax.swing.JPanel;

      import sun.awt.SunToolkit;

      public class TypeAhead_Demo extends JPanel
      {
         public TypeAhead_Demo()
         {
           final JButton b1 = new JButton("Button 1");
           final JTextField t1 = new JTextField(10);
           final JTextField t2 = new JTextField(10);
          
           this.add(t1);
           this.add(t2);
           this.add(b1);
          
           b1.addFocusListener(new FocusAdapter()
           {
             public void focusGained(FocusEvent event)
             {
               synchronized (this)
               {
                 try
                 {
                   wait(5000);
                 }
                 catch (Exception ex)
                 {
                  
                 }
                 System.out.println("request Focus to B2");
        
                 t1.requestFocus();
               }
             }
           });
          
           t1.addKeyListener(new KeyAdapter()
           {
             public void keyPressed(KeyEvent event)
             {
               if ( event.getKeyCode() == KeyEvent.VK_D )
               {
                 event.consume();
                 t2.requestFocus();
               }
             }
           }
           );
         }
        
         public static void main(String args[])
         {
           JFrame fr = new JFrame("FocusIssue");
           SunToolkit.setLWRequestStatus(fr, true);
           fr.getContentPane().add(new TypeAhead_Demo());
           fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           fr.pack();
           fr.setVisible(true);
         }
       }


      Test procedure:

      We need to follow steps in following manner.
        - Click on button->type "asdfg". Even before text appears, do alt+tab.

      Alt+tab needs to be pressed mean while focus is shifting from button to text field. Here, timing is very important factor to reproduce this bug.

      Results:
      Run test case and click on button first and type 'asdfg' as specified in the procedures.

         * JDK1.5.0_14 --> If we do alt+tab, "as" will be in tf1 and tf2 will be empty. Focus will be in tf1. (bug behavior)
         * JDK1.5.0_14 --> If we don't alt+tab, "as" will be in tf1 and "dfg" in tf2. Focus will be in tf2. (expected behavior with out alt+tab)
         * JDK 1.4.2-xx --> If we do or don't do alt+tab, "as" will be in tf1 and "dfg" in tf2. Focus will be in tf2. (expected behavior in both cases)

            ant Anton Tarasov (Inactive)
            kbteo Kim Teo
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: