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

[macosx] Converting MouseEvents may lead to inconsistent modifiers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 8
    • 7
    • client-libs
    • x86
    • os_x, windows_7

      FULL PRODUCT VERSION :
      java version "1.7.0_04"
      Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
      Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Using SwingUtilities.convertMouseEvent() or even the constructor of MouseEvent to convert (or clone) a MouseEvent from one Source to another, the modifiers set on the original event may differ from the modifiers of the converted event.

      I experienced this bug only with MouseEvents created by a click with button1 or button3 while the ALT-key was pressed.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Convert any MouseEvent triggered by a click with button 1 or button 3 while the alt-key was hold and check modifiers and/or button in the original event and in the converted one.

      Run the Example provided below, hold down ALT-key and click with left or right button (middle button seems to work). Note at the output.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected result: both events should report the same button and modifiers
      ACTUAL -
      USING BUTTON 1:
      original event :
      button=1,modifiers=Alt+Button1+Button2,extModifiers=Alt+Button1

      cloned event:
      button=1,modifiers=Button1+Button2,extModifiers=Button1+Button2

      USING BUTTON 3:
      original event: button=3,modifiers=Alt+Meta+Button2+Button3,extModifiers=Alt+Button3

      cloned event:
      button=2,modifiers=Alt+Button2+Button3,extModifiers=Alt+Button2+Button3

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;

      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;


      public class MouseConvertionSample extends JFrame {
          MouseConvertionSample () {
              this.setSize(100, 100);
              this.setVisible(true);
              this.addMouseListener(new MouseAdapter() {
                  @Override
                  public void mousePressed (MouseEvent e) {
                      MouseEvent e2 = SwingUtilities.convertMouseEvent(e.getComponent(), e, e.getComponent());
                      MouseEvent e3 = new MouseEvent(e.getComponent(),
                                                     e.getID(),
                                                     e.getWhen(),
                                                     e.getModifiers(),
                                                     e.getX(),
                                                     e.getY(),
                                                     e.getXOnScreen(),
                                                     e.getYOnScreen(),
                                                     e.getClickCount(),
                                                     e.isPopupTrigger(),
                                                     e.getButton());
                      System.out.println(e);
                      System.out.println(e2);
                      System.out.println(e3);
                  }
              });
          }
          
          public static void main (String[] args) {
              new MouseConvertionSample();
          }
      }

      ---------- END SOURCE ----------

            serb Sergey Bylokhov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: