How to detect mouse movement over node while button is pressed?

蓝咒 提交于 2019-11-30 13:47:02

The (source) node which handles the initial DRAG_DETECTED event should invoke sourceNode.startFullDrag(), then the target node will able to handle one of MouseDragEvents, for instance MOUSE_DRAG_OVER or MOUSE_DRAG_ENTERED event with respective targetNode.setOn<MouseDragEvent>() method.

One solution is to add an event filter to the scene which enables the sourceNode.startFullDrag(). This will work even if you start dragging the mouse outside of your canvas (if you want any space without nodes in your application).

Like this:

scene.addEventFilter(MouseEvent.DRAG_DETECTED , new EventHandler<MouseEvent>() {
    @Override
    public void handle(MouseEvent mouseEvent) {
        scene.startFullDrag();
    }
});

And then you could:

node.setOnMouseDragEntered(new EventHandler<MouseEvent>() {
    @Override
    public void handle(MouseEvent event) {
        led.setOn(true);
    } 
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!