-
Bug
-
Resolution: Duplicate
-
P4
-
7
-
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 ----------
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 ----------
- duplicates
-
JDK-7183783 MouseEvent doc should explain target of MOUSE_RELEASED and MOUSE_CLICKED
- Closed
-
JDK-7170657 [macosx] There seems to be no keyboard/mouse action to select non-contiguous items in List
- Closed