简体   繁体   English

在Java AWT中设置光标的位置

[英]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. 进行一些谷歌搜索后,我发现使用了Robot类。 But when I do this it calls the mouseMoved event implemented in MouseMotionListener which I don't want. 但是,当我执行此操作时,它将调用我不希望在MouseMotionListener中实现的mouseMoved事件。 Are there any other ways to set the position that wouldn't call that method? 还有其他方法可以设置不会调用该方法的位置吗?

The mouseMoved event will still fire no matter what you do, but you can overwrite it, so that it does nothing once fired. 无论您执行什么操作,mouseMoved事件仍将触发,但是您可以覆盖它,以便一旦触发它就不会执行任何操作。

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*/
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM