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

getLocationOnScreen() always returns (0, 0) for mouse wheel events

    Details

    • Subcomponent:
    • Resolved In Build:
      b80
    • CPU:
      generic
    • OS:
      windows

      Backports

        Description

        Run the following test on Windows and check coordinates (printed to stdout) for mouse pressed and mouse wheel events. If you see (0, 0) is always returned for event.getLocationOnScreen(), the bug is reproduced. On linux/solaris the test works correctly.

        import java.awt.*;
        import java.awt.event.*;

        import javax.swing.*;

        public class MouseWheelXY {
            public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
        new MouseWheelXY().createGUI();
        }
        });
            }
            private MouseAdapter mouseListener = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
        printEvent(e, "Button pressed");
        }
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
        printEvent(e, "Wheel moved");
        }
            };
            private void createGUI() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel labelPanel = new JPanel(new GridLayout(0, 1));
        frame.add(labelPanel);
        for (int index = 0; index < 10; index++) {
        String name = "Label " + index;
        JLabel label = new JLabel(name);
        label.setName(name);
        label.addMouseWheelListener(mouseListener);
        label.addMouseListener(mouseListener);
        labelPanel.add(label);
        }
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
            }
            private void printEvent(MouseEvent e, String message) {
        System.out.println(message);
        System.out.println("Name " + e.getComponent().getName());
        System.out.println("getPoint() " + e.getPoint());
        System.out.println("getLocationOnScreen() " + e.getLocationOnScreen());
            }
        }

          Activity

          Hide
          dav Andrei Dmitriev (Inactive) added a comment -
          BT2:EVALUATION

          We don't supply the CTOR with appropriate global x and y. Instead we put (0,0) in.
              jobject mouseWheelEvent = env->NewObject(mouseWheelEventCls,
                                                       mouseWheelEventConst,
                                                       target,
                                                       id, when, modifiers,
                                                       x+insets.left, y+insets.top,
                                                       0, 0,
                                                       clickCount, popupTrigger,
                                                       scrollType, scrollAmount,
                                                       roundedWheelRotation, preciseWheelRotation);

          At the same time we are extracting global coords for mouseevents from the lparam:
              int xAbs = GET_X_LPARAM(curMousePos);
              int yAbs = GET_Y_LPARAM(curMousePos);
              jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,
                                                  target,
                                                  id, when, modifiers,
                                                  x+insets.left, y+insets.top,
                                                  xAbs, yAbs,
                                                  clickCount, popupTrigger, button);
          Show
          dav Andrei Dmitriev (Inactive) added a comment - BT2:EVALUATION We don't supply the CTOR with appropriate global x and y. Instead we put (0,0) in.     jobject mouseWheelEvent = env->NewObject(mouseWheelEventCls,                                              mouseWheelEventConst,                                              target,                                              id, when, modifiers,                                              x+insets.left, y+insets.top,                                              0, 0,                                              clickCount, popupTrigger,                                              scrollType, scrollAmount,                                              roundedWheelRotation, preciseWheelRotation); At the same time we are extracting global coords for mouseevents from the lparam:     int xAbs = GET_X_LPARAM(curMousePos);     int yAbs = GET_Y_LPARAM(curMousePos);     jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,                                         target,                                         id, when, modifiers,                                         x+insets.left, y+insets.top,                                         xAbs, yAbs,                                         clickCount, popupTrigger, button);
          Hide
          vdyakov Victor Dyakov added a comment -
           - this is an issue reported against 7(7u),
           - there are now affected version 9 filed for this issue
           - 7u issues are transferred to Sustaining
          Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9
          or
          7u specific escalations might be reopen to Sustaining
          Show
          vdyakov Victor Dyakov added a comment -  - this is an issue reported against 7(7u),  - there are now affected version 9 filed for this issue  - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
          Hide
          vdyakov Victor Dyakov added a comment -
           - this is an issue reported against 7(7u),
           - there are now affected version 9 filed for this issue
           - 7u issues are transferred to Sustaining
          Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9
          or
          7u specific escalations might be reopen to Sustaining
          Show
          vdyakov Victor Dyakov added a comment -  - this is an issue reported against 7(7u),  - there are now affected version 9 filed for this issue  - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/e268e771e2eb
          User: serb
          Date: 2015-08-17 13:58:20 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/client/jdk/rev/e268e771e2eb User: serb Date: 2015-08-17 13:58:20 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/e268e771e2eb
          User: lana
          Date: 2015-09-01 20:27:06 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/e268e771e2eb User: lana Date: 2015-09-01 20:27:06 +0000

            People

            • Assignee:
              serb Sergey Bylokhov
              Reporter:
              art Artem Ananiev
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: