-编辑
我刚刚发现这是不可能的,但是我还能做其他什么来生成想要的视觉效果吗?
我正在使用JavaFX在DragBoard上设置dragView,但似乎找不到在拖动操作期间更改该图像的方法。
在拖动事件触发后,我尝试使用setDragView(MyImage)
,但这没用。
这完全有可能吗,还是我应该找到另一种方法?
以下代码:
// Called when drag starts
public void handleBlockDragDetected(PuzzleBlockView puzzleBlockView, PuzzleBlock puzzleBlock, GridPane blockPane)
{
ClipboardContent clipboardContent = new ClipboardContent();
clipboardContent.put(GameController.BLOCK_FORMAT, puzzleBlock);
Dragboard dragboard = blockPane.startDragAndDrop(TransferMode.MOVE);
dragboard.setDragViewOffsetX(20);
dragboard.setDragViewOffsetY(20);
dragboard.setDragView(puzzleBlockView.getSnapshot());
dragboard.setContent(clipboardContent);
blockPane.setVisible(false);
draggingBlock = puzzleBlockView;
}
// Called on dragOver detected
public void handleBlockDragOver(DragEvent event)
{
Dragboard dragboard = event.getDragboard();
if (dragboard.hasContent(BLOCK_FORMAT) && draggingBlock != null) {
dragboard.setDragView(new Image(getClass().getResource("/img/flag.png").toString()));
event.acceptTransferModes(TransferMode.MOVE);
}
}