JavaFX:在拖放过程中更改光标 [英] JavaFX: Changing cursor during drag and drop
问题描述
我正在尝试在拖放过程中更改Node上的光标,但是图像没有更改.我在节点的 DragDetectedEventHandler
中调用 setCursor()
.我也尝试过调用 getParent().setCursor()
并得到相同的结果.我也尝试过在其他各种事件处理程序中执行此操作,例如将鼠标向下拖动到上方.充其量,我可以在释放鼠标按钮后更改图像,但是在拖动过程中我需要图像有所不同.有人知道该怎么做吗?
I'm trying to change the cursor on my Node during a drag and drop, but the image is not changing. I'm calling setCursor()
in the DragDetectedEventHandler
of my node. I've also tried calling getParent().setCursor()
and had the same result. I've also tried doing this in the other various event handler such as mouse down and drag over. At best, I get the image to change after the mouse button is release, but I need the image to be different during the drag. Anyone know how to do this?
private class DragDetectedEventHandler implements EventHandler<MouseEvent> {
@Override
public void handle(MouseEvent mouseEvent) {
System.out.println("Drag Detected");
Dragboard db = startDragAndDrop(TransferMode.MOVE);
ClipboardContent content = new ClipboardContent();
content.putString("sample-drag-text");
db.setContent(content);
setCursor(_imageCursor);
mouseEvent.consume();
}
}
推荐答案
尝试
((Node) mouseEvent.getSource()).setCursor(Cursor.HAND);
如果不起作用,请发布您的完整类代码,其中包括DragDetectedEventHandler.
If doesn't work post your full code of class which includes your DragDetectedEventHandler.
这篇关于JavaFX:在拖放过程中更改光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!