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

前端 未结 2 699

Problem

You can add an event listener to a node which detects mouse movement over it. This doesn\'t work if a mouse button was pressed before you mo

相关标签:
2条回答
  • 2021-01-02 11:31

    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.

    0 讨论(0)
  • 2021-01-02 11:31

    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);
        } 
    });
    
    0 讨论(0)
提交回复
热议问题