JDK-4469090 : Menu cannot be opened with mnemonic if frame has no component in content pane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-06-12
  • Updated: 2001-06-13
  • Resolved: 2001-06-13
Related Reports
Duplicate :  
Description

Name: bsC130419			Date: 06/12/2001


java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, interpreted mode)


If a frame has no component in its content pane the menus cannot be opened with
their defined mnemonics. So the application cannot be used with keyboard only.

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

public class JDC2 extends JFrame{

	JDC2(String title){
		super(title);
		init();
		setSize(200, 200);
	}
	
	protected void init(){
		JMenuBar menuBar = new JMenuBar();
		JMenu menu = new JMenu("Test");
		menu.setMnemonic('T');
		menu.add(new JMenuItem("Subtest", 's'));
		menuBar.add(menu);
		setJMenuBar(menuBar);

	}
	
	public static void main(String [] args){
		try{
			UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
			JFrame frame = new JDC2("Mnemonic Test");
			Dimension screenSize =
  Toolkit.getDefaultToolkit().getScreenSize();
			Dimension frameSize = frame.getSize();
			frame.setLocation((screenSize.width - frameSize.width) /
2, (screenSize.height - frameSize.height) / 2);
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setVisible(true);
		}
		catch(Exception ex){
			ex.printStackTrace();
			System.exit(0);
		}
	}

}
(Review ID: 126265) 
======================================================================

Comments
EVALUATION This will be fixed as part of the 4389332, that is Swing will now install a KeyEventPostProcessor so that if no one consumes the KeyEvent bindings will be processed. This makes so that if focus is not a Swing component bindings will still work. scott.violet@eng 2001-06-13
13-06-2001