JDK-5036278 : modal JDialog does not disable use of mnemonic key events in other windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-04-22
  • Updated: 2005-05-03
  • Resolved: 2005-05-03
Related Reports
Duplicate :  
Relates :  
Description
Name: gm110360			Date: 04/22/2004


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

FULL OS VERSION :
Microsoft Windows 2000 Professional
5.0.2195 Service Pack 3 Build 2195

A DESCRIPTION OF THE PROBLEM :
I have a main application JFrame which opens additional JFrames.  When one of these other JFrames invokes a modal dialog, all windows (except the modal dialog) no longer respond to mouse events.  This is fine, except that when I click on the Windows Taskbar to bring focus to the main application window, I can use shortcut keys to open JMenus and "click" JButtons.  For example, I can now use Alt-F to open the file menu.  I believe this behaviour is incorrect.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Run the below application.
- In the JFrame that shows up, click the "open frame" button
- In the new JFrame that shows up, click the "open dialog" button
- Notice that both JFrames no longer respond to mouse events
- Use alt-tab to bring the original JFrame to focus
- Notice that the File menu and "open frame" button can be invoked by pressing "alt-f" and "alt-o"

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Keyboard events do not do anything.
ACTUAL -
Keyboard events are handled!

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class TestModal
{
	public TestModal()
	{
		try
		{
			UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
		}
		catch ( Exception e ) {}
		JFrame frame = new JFrame( "Main Window" );
		JMenuBar menubar = new JMenuBar();
		JMenu filemenu = new JMenu( "File" );
		filemenu.setMnemonic( 'F' );
		filemenu.add( new JMenuItem( "test" ) );
		menubar.add( filemenu );

		JButton button = new JButton( "open frame" );
		button.setMnemonic( 'O' );
		button.setActionCommand( "O" );
		button.addActionListener( new FrameInvoker( frame ) );

		JPanel panel = new JPanel();
		panel.add( button );
		panel.setPreferredSize( new Dimension( 500, 500 ) );

		frame.setContentPane( panel );
		frame.setJMenuBar( menubar );
		frame.pack();
		frame.setLocationRelativeTo( null );
		frame.setVisible( true );
	}
	
	public static void main(String[] args)
	{
		TestModal testModal = new TestModal();
	}
	
	public class FrameInvoker implements ActionListener
	{
		JFrame mParent;
		public FrameInvoker( JFrame parent )
		{
			mParent = parent;
		}

		public void actionPerformed( ActionEvent event )
		{
			JFrame frame = new JFrame( "Modal Parent" );
			JPanel panel = new JPanel();

			JButton button = new JButton( "open modal" );
			button.setMnemonic( 'O' );
			button.setActionCommand( "O" );
			button.addActionListener( new DialogInvoker( frame ) );

			panel.setPreferredSize( new Dimension( 200, 200 ) );
			frame.setContentPane( panel );
			frame.getContentPane().setLayout( new BorderLayout() );
			frame.getContentPane().add( button );
			frame.pack();
			frame.setLocationRelativeTo( mParent );
			frame.setVisible( true );
		}
	}
	
	public class DialogInvoker implements ActionListener
	{
		JFrame mParent;
		public DialogInvoker( JFrame parent )
		{
			mParent = parent;
		}

		public void actionPerformed( ActionEvent event )
		{
			JDialog dialog = new JDialog( mParent, "Modal Dialog", true );
			JPanel panel = new JPanel();
			panel.setPreferredSize( new Dimension( 200, 200 ) );
			dialog.setContentPane( panel );
			dialog.getContentPane().setLayout( new BorderLayout() );
			dialog.getContentPane().add( new JButton( "bla" ) );
			dialog.pack();
			dialog.setLocationRelativeTo( mParent );
			dialog.setVisible( true );
		}
		
	}
	
}
---------- END SOURCE ----------
(Incident Review ID: 208773) 
======================================================================

Comments
EVALUATION Showing the modal dialog disables input to BOTH frames and prevents them from being activated. However, for some reason, frame 1 can still be activated by clicking it's entry on the Windows task bar. After this, it seems key events are getting dispatched to the frame. I suspect this is an AWT bug. ###@###.### 2004-04-22 Name: osR10079 Date: 04/22/2004 I think this problem is almost the same as 4255200 (modal dialog should come to the front) We will try to fix it in next release. ###@###.### 2004-04-23 ====================================================================== This bug is a duplicate of either 4255200 or 4793073 (fixing either of them fixes this bug too). As 4793073 has a higher priority, closing this bug as duplicate of it. ###@###.### 2005-05-03 10:30:06 GMT
03-05-2005