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

[macosx] MouseEvent has wrong coordinates when using multiple monitors

    Details

    • Subcomponent:
    • Introduced In Version:
      7u6
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      Happens with both:
      java version " 1.7.0_25 "
      Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

      java version " 1.7.0_40-ea "
      Java(TM) SE Runtime Environment (build 1.7.0_40-ea-b29)
      Java HotSpot(TM) 64-Bit Server VM (build 24.0-b48, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X 10.8.4

      Darwin Geoffs-MacBook-Pro.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Using an external monitor (connected with a DisplayLink USB-to-DVI adapter)

      A DESCRIPTION OF THE PROBLEM :
      I have a laptop with an external monitor connected. When I open a Java window running my application and drag it to the external monitor, mouse events are received in the application with completely bogus Y screen coordinates. That is, MouseEvent.getYOnScreen() returns a number that's a few hundred pixels away from the real location.

      REGRESSION. Last worked in version 6u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached test program, drag it onto your second monitor, and wave your mouse over the frame.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No console output.
      ACTUAL -
      mismatch (1725,-341) != (1725,-161)
      mismatch (1710,-334) != (1710,-154)
      mismatch (1697,-325) != (1697,-145)
      mismatch (1691,-320) != (1691,-140)
      mismatch (1678,-310) != (1678,-130)
      mismatch (1662,-298) != (1662,-118)

      etc...

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class Test extends MouseAdapter implements Runnable {
        public void mouseMoved(MouseEvent e) {
          Point p = e.getPoint();
          SwingUtilities.convertPointToScreen(p, e.getComponent());
          if (p.x != e.getXOnScreen() || p.y != e.getYOnScreen()) {
            System.out.println( " mismatch ( " + p.x + " , " + p.y + " ) != ( " + e.getXOnScreen() + " , " + e.getYOnScreen() + " ) " );
          }
        }

        public void run() {
          JPanel panel = new JPanel();
          panel.setPreferredSize(new Dimension(300, 300));
          panel.addMouseMotionListener(this);

          JFrame frame = new JFrame();
          frame.add(panel);
          frame.pack();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
        }

        public static void main(String[] args) {
          SwingUtilities.invokeLater(new Test());
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      The relative coordinates seem to be correct. My workaround is to use reflection to overwrite MouseEvent.xAbs and MouseEvent.yAbs with values obtained from SwingUtilities.convertPointToScreen.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                azvegint Alexander Zvegintsev (Inactive)
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: