Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5036278

modal JDialog does not disable use of mnemonic key events in other windows

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      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)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                art Artem Ananiev
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: