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

Keyboard Accelerator implementation not MenuElement-aware

    XMLWordPrintable

Details

    • beta2
    • generic
    • generic

    Description



      Name: boT120536 Date: 01/10/2001


      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      This is not a bug but a limitation in the implementation of the
      processKeyBinding and processBindingForKeyStrokeRecursive methods of JMenuBar.
      processKeyBinding is overridden from JComponent so that when the
      KeyboardManager passes key events to any registered menubars through
      processKeyBinding, it recursively scans through JMenus and JMenuItems, looking
      for components that are registered for the event. All this allows keyboard
      menu accelerators to work even when menus aren't visible...

      The problem is that these overridden methods are implemented to recursively
      scan JMenus and JMenuItems, specifically, instead of using the MenuElement
      interface. So developers who make additional components that implement
      MenuElement can't get accelerators to work properly. It seems easy instead to
      recursively scan through MenuElements using the getSubElements and getComponent
      methods of that interface. If the JMenuBar (and other Swing code, for that
      matter) stuck to the MenuElement interface in cases like this, it would make
      menu component development simpler (yes, I am in fact making a MenuElement that
      is not a JMenuItem...).

      So, instead of implementing the mentioned methods with 'instanceof JMenuItem'
      and 'instanceof JMenu' expressions, please modify this code to use the
      MenuElement interface, checking binding with something
      like 'menuelement.getComponent().processKeyBinding(...)' (or give me the
      possible good reason why it's not implemented that way to begin with :) Thanks!
      (Review ID: 111589)
      ======================================================================

      Attachments

        Activity

          People

            peterz Peter Zhelezniakov
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: