JDK-7182068 : [macosx] Converting MouseEvents may lead to inconsistent modifiers
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x,windows_7
  • CPU: x86
  • Submitted: 2012-07-06
  • Updated: 2012-07-17
  • Resolved: 2012-07-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8Resolved
Related Reports
Duplicate :  
Description
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 ----------

Comments
EVALUATION Bug in SwingUtilities.convertMouseEvent(). It ignores extended statet of the event. "getModifiers()" should be replaced with "getModifiers() | getModifiersEx()"
17-07-2012