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

JDesktopPane consumes every ESCAPE KeyEvent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.1
    • client-libs



      Name: jk109818 Date: 07/31/2002


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

      FULL OPERATING SYSTEM VERSION :
      Windows NT Version 4.0
      ServicePack 5

      A DESCRIPTION OF THE PROBLEM :
      Suppose the focus of your swing application is located in a
      JInternalFrame. When you press the ESCAPE key, the
      corresponding KeyEvent is consumed by the JDestopPane und
      not delivered to the parent component of the JDesktopPane.

      For example if the accelerotor of a JMenuItem is set to
      ESCAPE, the JMenuItem is never invoked if you press ESCAPE
      and the focus is inside of an JInternalFrame.

      I know that the ESCAPE key is designed for cancelling
      resizing (CTRL+F8)and moving (CTRL+F7) of JInternalFrames,
      but the KeyEvent is always consumed, not just when I am
      actually moving or resizing an JInternalFrame.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and start the example application below
      2. Set the cursor (focus) into the JTextArea contained in
      the JInternalFrame
      3. Press ESCAPE and the JMenuItem registered to the ESCAPE-
      Key is not invoked because the KeyEvent is consumed by the
      JDesktopPane

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The KeyEvent belonging to the pressed ESCAPE key shout not
      be consumed by the JDesktopPane.
      Instead it shoulb be delivered to the parent component.
      Pression the ESCAPE-Key in my sample application shout
      invoke the associated JMenuItem whether or not i'm in an
      JInternalFrame.

      This bug can be reproduced rarely.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class EscapeTest{
      public static void main(String[] argv){
      final JFrame f=new JFrame();
      JMenu m=new JMenu("Submenu");
      JMenuItem mi=new JMenuItem("ESCAPE menu item");
      JMenuBar mb=new JMenuBar();
      mb.add(m);
      m.add(mi);
      f.setJMenuBar(mb);
      f.setBounds(50,50,400,400);

      // set the ESCAPE-Key as accelerator for the MenuItem
      mi.setAccelerator(KeyStroke.getKeyStroke("ESCAPE"));

      // add an ActionListener to the MenuItem that shows a message
      if the menuItem is invoked
      // the action can be invoked by
      // - selecting the menu
      // - pressing the ESCAPE key
      mi.addActionListener(
      new ActionListener(){
      public void actionPerformed(ActionEvent ae){
      JOptionPane.showMessageDialog
      (f, "ESCAPE menu item invoked.", "Exit", JOptionPane.INFORMATION_MESSAGE);
      }
      }
      );

      // create a JDesktopPane and a JInternalFrame
      JDesktopPane desktopPane=new JDesktopPane();
      JInternalFrame internalFrame=new JInternalFrame("Internal
      frame", true, true, true, true);
      internalFrame.setBounds(10,10,300,100);
      desktopPane.add(internalFrame);
      internalFrame.setVisible(true);
      // add a JTextArea to the JInternalFrame
      internalFrame.getContentPane().add(new JTextArea("Press ESCAPE
      here and the JMenuItem will\nNOT be invoked!"));

      JSplitPane splitPane=new JSplitPane(JSplitPane.VERTICAL_SPLIT);
      splitPane.setTopComponent(desktopPane);
      splitPane.setBottomComponent(new JTextArea("Press ESCAPE here
      and the JMenuItem will be invoked!"));
      splitPane.setDividerLocation(200);

      f.getContentPane().add(splitPane);

      // show the Frame
      f.show();
      }
      }

      ---------- END SOURCE ----------
      (Review ID: 145634)
      ======================================================================

            joutwatesunw Joshua Outwater (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: