JDK-4893913 : JMenuItem's setAccelerator and setMnemionic doesn't work in JApplet via plugin
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-07-22
  • Updated: 2003-11-19
  • Resolved: 2003-11-19
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 07/21/2003


FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When running a JApplet via the Java Plugin, mnemonics and accelerators assigned to JMenuItems off of the JApplet's JMenuBar do not trigger the associated event.

I expect the browser is receiving the focus and I would also expect this is unworkaroundable behavior.  However, it would be nice if the JavaDoc mentioned that setAccelerator and setMnemonic may produce unreliablwe results when used in a JApplet embedded in a browser page.

If the user manually provides focus to some component in the JApplet, the mnemonics and accelerators function correctly.  However, if the user then minimizes and restores the JApplet, the accelerators and mnemonics again become unavailable.

If a JFrame is used instead of a JApplet, the mnemonics and accelerators work correctly.  Only when a JMenuBar is attached to a JApplet and used via the Java Plugin is the erroneous behavior observed.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the included test case by bringing up the applet via the Java Plugin and attempt to use the assigned mnemonic (alt-a) or the assigned accelerator (delete).

The associated actions should not be executed.  Then, click the 'focus' button and again attempt to use the mnemonic and accelerator - they should succeed.

Then minimize and restore the applet and attempt to use the accelerator and mnemonic - the attempt should fail.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Either the applet should be able to gain focus or the fact that accelerators and mnemonics used in a JApplet are unreliable should be documented.
Accelerators and mnemonics failed unless a component of the JApplet was explicitly provided focus by the user.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

public class FocusSample extends JApplet {

    public void init() {
        super.init();
    }
    
	public FocusSample() {
		JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

		JMenu menu = new JMenu("A Menu");

        menuBar.add(menu);
		menu.setMnemonic(KeyEvent.VK_A);
        final JButton button=new JButton("Focus");

		JMenuItem menuItem = menu.add(new AbstractAction("Focus") {
            int count=0;
			public void actionPerformed(ActionEvent e) {
                button.setText("Focus " + count++);
			}
		});

        getContentPane().setLayout(new GridLayout(0, 1));
        getContentPane().add(button);
		menuItem.setMnemonic(KeyEvent.VK_D);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
		setSize(new Dimension(300, 300));
	}
}



---------- END SOURCE ----------
(Incident Review ID: 182846) 
======================================================================

Comments
EVALUATION Using appletviewer to run the testcase attached, generate the same result. Reassign to swing team. ###@###.### 2003-07-24 Name: azR10139 Date: 11/17/2003 Swing does not handle the focus. Recategorizing bug to AWT team. ###@###.### 11/17/2003 ====================================================================== Name: atR10251 Date: 11/18/2003 This is not a problem of accelerators and mnemonics but focus. The original focus problem risen in the context of the bug #4922092 was resolved. The fix will be integrated in Tiger. Thus this bug is a duplicate of 4922092. ###@###.### 2003-11-18 ======================================================================
18-11-2003