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

前端 未结 2 698

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

    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() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            scene.startFullDrag();
        }
    });
    

    And then you could:

    node.setOnMouseDragEntered(new EventHandler() {
        @Override
        public void handle(MouseEvent event) {
            led.setOn(true);
        } 
    });
    

提交回复
热议问题