简体   繁体   English

JavaFX8 startFullDrag() 无效

[英]JavaFX8 startFullDrag() not effective

I want to connect two circles by drag & drop.我想通过拖放连接两个圆圈。

Pane p = new Pane();

Circle c1 = new Circle(5);
c1.relocate(10,10);
c1.addEventFilter(MouseEvent.DRAG_DETECTED, e -> {
    c1.startFullDrag();
    System.out.println("started");
});

Circle c2 = new Circle(5);
c2.relocate(40,40);
c2.addEventFilter(DragEvent.ANY, e -> System.out.println("any") );
c2.addEventFilter(DragEvent.DRAG_ENTERED, e -> System.out.println("entered") );

p.getChildren().addAll(c1, c2);

That's what I tried.这就是我尝试过的。
When drag&dropping from the left circle c1 to the right circle c2 , the DRAG_DETECTED Event will work.当从左圆c1拖放到右圆c2DRAG_DETECTED事件将起作用。
But the DragEvent.ANY or DragEvent.DRAG_ENTERED will not be triggered.但不会触发DragEvent.ANYDragEvent.DRAG_ENTERED

I also tried consuming mouse events in DRAG_DETECTED but that doesn't change anything either.我还尝试在DRAG_DETECTED使用鼠标事件,但这也没有任何改变。 I also tried using setOnDragEntered(EventHandler) and addEventHandler(EventType, EventHandler) instead of addEventFilter(EventType, EventHandler) but none works.我还尝试使用setOnDragEntered(EventHandler)addEventHandler(EventType, EventHandler)而不是addEventFilter(EventType, EventHandler)但都没有工作。

Why does c2 not receive any DragEvent s?为什么c2没有收到任何DragEvent s?

startFullDrag() will trigger MouseDragEvents, but not DragEvents. startFullDrag()将触发 MouseDragEvents,但不会触发 DragEvents。

replace addEventFilter(DragEvent.DRAG_ENTERED, ... );替换addEventFilter(DragEvent.DRAG_ENTERED, ... ); with addEventFilter(MouseDragEvent.DRAG_ENTERED, ... );使用addEventFilter(MouseDragEvent.DRAG_ENTERED, ... );

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

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