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

REGRESSION: Accelerator vs. TransferHandler

XMLWordPrintable

    • b53
    • x86
    • windows_2000

      Name: sv35042 Date: 10/18/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 :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      Menu item accelerators have a hard time coping with the new
      Swing Data Transfer introduced in JDK1.4. Namely, they are
      ignored even if the (default) clipboard support is disabled
      from a component, i.e. setTransferHandler(null). In that
      case, it only seems reasonable that the key event would be
      passed on so that some other component (in this case, the
      menu item) would process it. Hardly a critical issue but as
      it worked OK with JDK1.3.1...

      REGRESSION. Last worked in version 1.3.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached demo.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Ctrl-C does nothing with the tree (as the transfer handler
      has been nullified) so Èì kinda expected the action listener
      of the menu item would've been triggered. It didn't.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class TreeTest
          extends JFrame
      {
          public static void main( String[] args )
          {
              TreeTest t = new TreeTest();
              t.buildUi();
              t.show();
          }
          public void buildUi()
          {
              JMenuBar menuBar = new JMenuBar();
              JMenu menu = new JMenu();
              JMenuItem copyItem = new JMenuItem( "Copy" );
              copyItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_C,
      KeyEvent.CTRL_MASK ) );
              menu.setText( "File" );
              copyItem.setText( "Copy" );
              menuBar.add( menu );
              menu.add( copyItem );
              setJMenuBar( menuBar );
              copyItem.addActionListener( new ActionListener()
              {
                  public void actionPerformed( ActionEvent evt )
                  {
                      System.out.println( "gee, why am i not called via ctrl-c?" );
                  }
              });
              JTree tree = new JTree();
              tree.setTransferHandler( null ); // go away, evil default handling
              // unregisterKeyboardAction() does not work either, btw...
              getContentPane().add( tree );
              setSize( 640, 480 );
          }
          protected void processWindowEvent( WindowEvent evt )
          {
              if ( evt.getID() == WindowEvent.WINDOW_CLOSING )
              {
                  System.exit( 0 );
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
        Hook the action listener of the menu item directly to the
      tree via registerKeyboardAction. Hardly an elegant approach.

      Release Regression From : 1.4
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Review ID: 158994)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: