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

Add a setDefualtCancelButton to a JFrame like setDefualtButton

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      A DESCRIPTION OF THE REQUEST :
      There is already a defualt button for when you press enter on a JFrame, there shoulqd be a defualt cancel button for when the user presses escape

      JUSTIFICATION :
      This is the way most if not all operating systems handel the esc key, and as of now, I need to loop through and add the key listener to all the compoenents.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      fires ActionPerformed on the defualtCancelButton set using JFrame.setDefualtCancelButton
      ACTUAL -
      this feature does not exist yet

      CUSTOMER SUBMITTED WORKAROUND :
      public static void setupEscCancel(final JFrame frame){
      KeyListener cancelKeyListener=new KeyListener() {
      public void keyTyped(KeyEvent e) {}
      public void keyPressed(KeyEvent e) {}
      public void keyReleased(KeyEvent e) {if (e.getKeyCode()==27) frame.dispose();}};
      addListenerToContainedComponents(frame.getRootPane(),cancelKeyListener);
      }
      public static void addListenerToContainedComponents(Container componentToAddTo,KeyListener keyListener) {
      for (Component component : componentToAddTo.getComponents()) {
      if (component instanceof Container)
      addListenerToContainedComponents((Container) component, keyListener);
      component.addKeyListener(keyListener);
      }
      }
      ###@###.### 2005-06-17 12:02:37 GMT

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: