Ben Lakey Ben Lakey - 1 year ago 79
Java Question

How do I set the position of the mouse in Java?

I'm doing some Swing GUI work with Java, and I think my question is fairly straightforward; How does one set the position of the mouse?

Answer Source

You need to use Robot

This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.

Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue. For example, Robot.mouseMove will actually move the mouse cursor instead of just generating mouse move events...