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

Java 8 - AWT Robot mouseMove fails on Windows 10 1709

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 - 1709


      A DESCRIPTION OF THE PROBLEM :
      JDK-8196030 (https://bugs.openjdk.java.net/browse/JDK-8196030?attachmentOrder=desc) contains in the first comment that the ticket does not affect Java 8. Unfortunately, that is not true. Running the SimpleAWTRobotTest.java (found in the original ticket) on some Windows 10 - 1709 systems fail, because the Robot.mouseMove() moves the mouse to the wrong part of the screen.

      Failing systems need to be 1080p with a 15" or less monitor. Even with the display scaling set to 100%, the AWT Robot still moves the wrong coordinates.

      I've seen it fail at 1080p 100% scale on a 13" laptop and a 15" laptop, but pass on a 65" screen. It seems Windows is "compensating" for the smaller screen and Java is not handling it. It seem to work reliably under Linux.

      See discussion of the problem affecting AssertJ Swing here: https://github.com/joel-costigliola/assertj-swing/issues/235

      This ticket is a request to backport JDK-8196030 to Java 8.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See attached test (lifted verbatim from ORC-8196030).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Move the mouse to the correct part of the screen.
      ACTUAL -
      Moves the mouse to the wrong part of the screen.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import java.awt.Robot;
      import java.awt.event.InputEvent;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.SwingUtilities;

      /**
       * Simple standalone AWT robot test.
       */
      public class SimpleAWTRobotTest {

          private boolean clicked = false;

          public void initGUI() {
              JFrame frame = new JFrame("Simple AWT Robot Test");
              frame.setLayout(new BorderLayout());
              frame.setUndecorated(true);
              frame.setLocation(300, 300);

              JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              panel.setPreferredSize(new Dimension(100, 100));
              frame.add(panel);

              JButton button = new JButton("Click me");
              button.addActionListener(e -> clicked = true);
              panel.add(button, BorderLayout.CENTER);

              frame.pack();
              frame.setVisible(true);
          }

          public void test() throws Exception {
              final Robot robot = new Robot();

              SwingUtilities.invokeAndWait(() -> {
                  this.initGUI();
              });
              SwingUtilities.invokeAndWait(() -> {
                  //robot.mouseMove(0, 0);
                  robot.mouseMove(350, 350);
              });
              Thread.sleep(500);
              SwingUtilities.invokeAndWait(() -> {
                  robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
              });
              Thread.sleep(500);
              SwingUtilities.invokeAndWait(() -> {
                  robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
              });
              Thread.sleep(500);
              if (clicked) {
                  System.out.println("PASSED");
              } else {
                  System.out.println("*** FAILED");
              }
              System.exit(0);
          }

          public static void main(String[] args) throws Exception {
              new SimpleAWTRobotTest().test();
          }
          
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use Java 11

      FREQUENCY : always


            bvaidya Balchandra Vaidya
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: