JDK-6668749 : awt: requestFocus not working while moving away from proc. using ALT-TAB in jdk 5.0 upd 14
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0u14
  • Priority: P2
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-02-28
  • Updated: 2011-01-19
  • Resolved: 2008-05-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0u14Resolved
Related Reports
Relates :  
Description
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)

Comments
EVALUATION I observe the following behavior with different JDK releases: 1. Without pressing Alt+Tab all the JDK releases behave the same way: 'as' is displayed in tf1, 'dfg' is displayed in tf2, focus is in tf2. 2. With Alt+Tab, JDK 1.4.2_11: 'as' is in tf1, 'fg' is in tf2, focus is in tf2 3. With Alt+Tab, JDK 1.5.0_11: 'as' is in tf1, tf2 is empty, focus is in tf2 4. With Alt+Tab, JDK 6u1 & JDK 7-b21: both tf1 and tf2 are empty, focus is in tf2
06-03-2008