JDK-4841881 : Alt tab with Windows L&F moves focus to the application menubar
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-04-03
  • Updated: 2006-04-05
  • Resolved: 2006-04-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.
JDK 6
6 b79Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Name: ks84122			Date: 04/02/2003


The problem below is reproducible with JDK 1.4.1 and 1.4.2 build 19 on windows 2000. The problem isn't reproducible with some of the earlier builds of 1.4.2 (build 03, for example). However, it seems to have resurfaced again in the latest builds.

Original description from Borland:
==================================

Very frequently only with the Windows Look and Feel doing an Alt-Tab from one application to another and back results in focus being moved to the first menu item.

Run the program below.  Focus starts out in the text field.  Use Alt-Tab to move to another application (e.g. Notepad) and back multiple times. Usually by the second or third time the File menu item is selected.  On some machines happens every time.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Frame1 extends JFrame {
  JPanel contentPane;
  JMenuBar jMenuBar1 = new JMenuBar();
  JMenu jMenuFile = new JMenu();
  JMenuItem jMenuFileExit = new JMenuItem();
  JMenu jMenuHelp = new JMenu();
  JMenuItem jMenuHelpAbout = new JMenuItem();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();

  //Construct the frame
  public Frame1() {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(gridBagLayout1);

    this.setTitle("Frame Title");
    jMenuFile.setText("File");
    jMenuFileExit.setText("Exit");

    jMenuHelp.setText("Help");
    jMenuHelpAbout.setText("About");

    jMenuFile.add(jMenuFileExit);
    jMenuHelp.add(jMenuHelpAbout);
    jMenuBar1.add(jMenuFile);
    jMenuBar1.add(jMenuHelp);

    jLabel1.setLabelFor(jTextField1);
    jLabel1.setText("Label");
    jLabel1.setDisplayedMnemonic('l');
    jTextField1.setText("text");

    contentPane.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
      GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    contentPane.add(jTextField1,  new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
      GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    this.setJMenuBar(jMenuBar1);
  }


  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
     }
    catch (Exception ex) {
      ex.printStackTrace();
    }

    Frame1 frame = new Frame1();
    frame.validate();
    frame.setSize(200, 100);
    frame.setLocation(200, 200);
    frame.setVisible(true);
  }
}
(Review ID: 165756) 
======================================================================
Please refer to 6458497. I have verified (on mustang build 93) a report that highlights that the focus still stays on the menu bar. This can be reproduced with the test case in 4841881 by quickly pressing the ALT-TAB buttons.

Comments
SUGGESTED FIX --- awt_Window.cpp 2006-03-04 11:35:13.000000000 +0300 *************** *** 156,165 **** } m_grabbed = TRUE; m_grabbedWindow = this; ! if (GetHWnd() != sm_focusedWindow) { _ToFront(env->NewGlobalRef(GetPeer(env))); } - // Global ref was deleted in _ToFront } void --- 156,168 ---- } m_grabbed = TRUE; m_grabbedWindow = this; ! if (sm_focusedWindow == NULL) { ! // we shouldn't perform grab in this case ! Ungrab(); ! } else if (GetHWnd() != sm_focusedWindow) { _ToFront(env->NewGlobalRef(GetPeer(env))); + // Global ref was deleted in _ToFront } }
06-03-2006

EVALUATION the problem is that grab() is called when the frame is deactivated (and new active window is not one of its owned windows). I think we should send ungrab event in this situation and grab nothing.
27-02-2006

EVALUATION When we show heavyweight popup Swing graps the window, if we quickly do alt+tab in this case sometimes ungrab event doesn't come and JMenu stay selected reassigned to AWT
08-02-2006

EVALUATION I've reopened this as it is reproducible with 1.6 and is causing grief with a number of apps, including NetBeans. Take a look at http://www.netbeans.org/issues/show_bug.cgi?id=46826 for a list of the NetBeans customers that have reported this. I'll also say that the problem is a worse then outlined in the description. In particular with NetBeans in some cases after releasing the alt or tab keys focus snaps back to NetBeans!
31-01-2006

EVALUATION Name: azR10139 Date: 04/07/2003 This is another side-effect of fix for bug 4766477. In the fix we are removing the code that cancels popup on deactivation of the invoker's frame. What happens now: the user presses <ALT>, then <TAB>, but we are receiving only <ALT> key pressing event. If user releases <ALT> before releasing <TAB> we will receive <ALT> release event and activate menu. After this frame losts focus and deactivates. Without the fix for bug 4766477 the code that detects deactivation of the frame cancels popup by setting empty selected path in MenuSelectionManager. Then menu is becames deselected and focus returns to where it was before menu is activated. User does even feels that menu was activated. This bug will be fixed in the next release. ###@###.### 04/07/2003 ====================================================================== Can not be reproduced on all 1.5 builds. Closeng as not reproducible. ###@###.### 2003-09-19
19-09-2003