This content has been marked as final. Show 4 replies
Yes, using MouseInfo, Robot, and a Timer you can do just that. Use a Timer--javax.swing.Timer to get a loop going and check MouseInfo when it activates, if your mouse is out of the Panel, then move it back.
You may also be able to accomplish this with just a MouseMotionListener, but I'd be afraid of getting out of the screen and not being notified.
I looked into Robot and MouseInfo, got it to work.The code is being executed by a custom Thread, and sometimes i get a 'java.lang.InterruptedException: sleep interrupted' error, wich is being thrown from the robot.
Any ideas why this is happening and how it can be solved?
java.lang.InterruptedException: sleep interrupted at java.lang.Thread.sleep(Native Method) at java.awt.Robot.delay(Unknown Source) at java.awt.Robot.autoDelay(Unknown Source) at java.awt.Robot.afterEvent(Unknown Source) at java.awt.Robot.mouseMove(Unknown Source)