JDK-6689567 : Not able to switch focus between two frames of the same Java application using q
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u5
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 2008-04-16
  • Updated: 2011-04-28
Related Reports
Relates :  
Description
OPERATING SYSTEM(S)
-------------------
All

FULL JDK VERSION(S)
-------------------
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b25)
Java HotSpot(TM) Client VM (build 12.0-b01, mixed mode)

java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode)

java version "1.5.0_15"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
Java HotSpot(TM) Client VM (build 1.5.0_15-b04, mixed mode)

DESCRIPTION
-----------
In any look-and-feel and on any platform, quick Alt-Tab does not switch focus between two frames of the same Java application properly under certain circumstances (the example described here is when the application menu has the focus).

The problem seems similar to 6458497, and may be related, but I could not find any existing bug for the exact issue described in this report.

RECREATION INSTRUCTIONS
-----------------------
1. Compile and launch the sample code given below. Two windows will come up.
2. Click on the Menu of the currently active window.
3. Try to switch focus between two windows using quick Alt-Tab.
4. Focus shifts to the other frame.
5. Use quick Alt-Tab again to switch focus.

Observed result:
Focus stays in the same window.

Expected result:
Focus should shift to the other window.

The behaviour is not completely consistent, but it seems that two quick Alt-Tab presses usually makes the focus shift to the other window.

TESTCASE SOURCE
---------------
import java.awt.*;
import javax.swing.*;

public class AltTab {
  public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel(UIManager
             .getSystemLookAndFeelClassName());
    } catch(Exception e) {
    }

    JFrame frame = new JFrame("Alt-Tab Frame");
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    JMenu fileMenu = new JMenu("File");

    char fileMenuMnemonic = 'F';
    fileMenu.setMnemonic(fileMenuMnemonic);
    menuBar.add(fileMenu);
    frame.setSize(100,100);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    JFrame frame1 = new JFrame("Alt-Tab Frame");
    JMenuBar menuBar1 = new JMenuBar();
    frame1.setJMenuBar(menuBar1);
    JMenu fileMenu1 = new JMenu("File");

    char fileMenuMnemonic1 = 'F';
    fileMenu1.setMnemonic(fileMenuMnemonic1);
    menuBar1.add(fileMenu1);
    frame1.setSize(100,100);
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame1.setVisible(true);
  }
}

Comments
EVALUATION The grab issue is similar to 6458497 that covers the case when user switches between Java frame and another application. Swing receives two Alt events - up and down (the Tab event is coming after the Alt events for some reason) and requests focus on menubar. The fix for 6458497 is to ignore the focus requests if the foreground window is out of the Java application. The fix doesn't work when user switches between two Java frames.
08-07-2008

EVALUATION I wasn't able to reproduce the issue. >> 2. Click on the Menu of the currently active window. >> 3. Try to switch focus between two windows using quick Alt-Tab. >> 4. Focus shifts to the other frame. In my case when I click on the menu it grabs alt-tab and the focus stays on the same window. I tried this on Ununtu 7.10, GNOME, metacity window manager Solaris 10, Java Desktop System The results are the same. Could you please provide more information about OS, window manager, special settings etc. The request says that OS is sol2.5.1 - SunOS 5.5.1 (release date - May 1996) which is not supported. Is the issue reproducible on other machines?
26-06-2008

EVALUATION Is this a grabbing issue?
14-05-2008