Letrstotheprez
Letrstotheprez

Reputation: 622

Setting the position of the cursor in java awt

I've been looking at how to programmatically set the position of the cursor. Doing some googling I found the use of the Robot class. But when I do this it calls the mouseMoved event implemented in MouseMotionListener which I don't want. Are there any other ways to set the position that wouldn't call that method?

Upvotes: 0

Views: 521

Answers (1)

sorifiend
sorifiend

Reputation: 6307

The mouseMoved event will still fire no matter what you do, but you can overwrite it, so that it does nothing once fired.

You can overwrite the listener of the component that you are moving the mouse on, so that only that component will ignore the event but others components will trigger properly.

    myComponent.addMouseMotionListener(new MouseMotionAdapter()
    {
        @Override
        public void mouseMoved(MouseEvent e)
        {
            /*Do Nothing*/
        }
    });

Upvotes: 1

Related Questions