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

MouseEvent extended modifiers include wrong keyboard modifiers.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_02"
      Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 5.2.3790]

      A DESCRIPTION OF THE PROBLEM :
      The extended modifiers from a mouse event has spurious keyboard modifiers on the released and clicked event from the second or third mouse button. For example, clicking the second mouse button will result in a mousePressed event with the Button2 extended modifier (correct), but a mouseReleased and then mouseClicked with the Alt extended modifier. I was not _anywhere_ near the Alt key on my keyboard.

      I do realize that the pre 1.4 modifiers intermixed mouse buttons and keyboard modifiers, but the extended modifiers were introduced to solve this problem, as I understand it.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the test case.
      2. Left click on the label "Click me!".
      3. Note the extended modifers on the pressed, released and clicked event. (These are correct.)
      4. Middle click the label using a three button mouse.
      5. Note the extended modifiers on the pressed, released and clicked event. The pressed modifiers are correct (button2). The released or clicked event, on the other hand, has Alt as a modifier, even though it certainly isn't pressed on the keyboard.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I'd expect the keyboard modifiers on the released and clicked event to be the same as for the pressed event. That is none, if no keys are pressed.
      ACTUAL -
      Pressed.
      Normal modifiers: 8, Alt+Button2
      Extended modifiers: 2048, Button2
      ------------------------------------------------
        Released.
      Normal modifiers: 8, Alt+Button2
      Extended modifiers: 512, Alt
      ------------------------------------------------
      Clicked.
      Normal modifiers: 8, Alt+Button2
      Extended modifiers: 512, Alt
      ------------------------------------------------

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class TestSwingMouseEvents {
        static {
          try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          }
          catch (Exception e) { }
        }
        
        public static void main(String[] args) {
          JFrame mainWindow = new JFrame("MouseEvent bug.");
          JLabel label = new JLabel("Click me!");
          label.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              System.out.println("Pressed.");
              printMouseEventInfo(e);
            }
            public void mouseReleased(MouseEvent e) {
              System.out.println("Released.");
              printMouseEventInfo(e);
            }
            public void mouseClicked(MouseEvent e) {
              System.out.println("Clicked.");
              printMouseEventInfo(e);
            }
          });
          label.setFont(new Font("Helvetica", Font.PLAIN, 48));
          mainWindow.getContentPane().add(label);
          
          mainWindow.pack();
          mainWindow.setVisible(true);
        }
        
        public static void printMouseEventInfo(MouseEvent evt) {
          System.out.println("Normal modifiers: " + evt.getModifiers() + ", " + MouseEvent.getMouseModifiersText(evt.getModifiers()));
          System.out.println("Extended modifiers: " + evt.getModifiersEx() + ", " + MouseEvent.getModifiersExText(evt.getModifiersEx()));
          System.out.println("------------------------------------------------");
        }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            dav Andrei Dmitriev (Inactive)
            Reporter:
            dav Andrei Dmitriev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: