简体   繁体   English

使用 JavaFX 拖放

[英]Drag n Drop with JavaFX

So, I've got a uni project to do and we gotta do a drag and drop with some sort of rectangle in JavaFX.所以,我有一个 uni 项目要做,我们必须在 JavaFX 中使用某种矩形进行拖放。 And so, it works, but when the drop is done, it does not end, it just stays like I didn't drop.所以,它起作用了,但是当下降完成时,它并没有结束,它就像我没有下降一样。 Although, my code is pretty short, here it is, thank's for your help ^^.虽然,我的代码很短,但在这里,谢谢你的帮助^^。

That's the code of the destination这是目的地的代码

    this.setOnDragOver(event ->
    {
    if(event.getGestureSource() != this && event.getDragboard().hasContent(DataFormat.PLAIN_TEXT))
            {
                event.acceptTransferModes(TransferMode.MOVE);
            }
            event.consume();
        });

        this.setOnDragDropped(event ->
        {
            for(StepIG e : world)
            {
                // If the StepIG is the one we need to drag
                if(event.getDragboard().getContent(DataFormat.PLAIN_TEXT).equals(e.getId()) && event.getTransferMode().equals(TransferMode.MOVE))
                {
                    e.reSetPosition((int)event.getX(), (int)event.getY();
                    world.notifyAll();
                }
            }
            event.setDropCompleted(true);
            event.consume();
        });
this.setOnDragDone(event -> System.out.println("smthing"));

and the code of the source:和源代码:

        this.setOnDragDetected(event ->
        {
            Dragboard dragboard = this.startDragAndDrop(TransferMode.MOVE);
            ClipboardContent ccontent = new ClipboardContent();
            ccontent.putString(this.getEtape().getId());
            dragboard.setContent(ccontent);
            event.consume();
        });

PS: I forgot to mention that I isolated the problem to the function "setOnDragOver()" PS:我忘了提到我将问题隔离到 function "setOnDragOver()"

Okay so, after a few hours of research I found the answer, my jfx version couldn't handle DnD... I guess... So I had to add a VM argument: -Djdk.gtk.version=2, plus, if you want to add an image or whatever anything else, add this VM argument: -Dprism.forceGPU=true好吧,经过几个小时的研究,我找到了答案,我的 jfx 版本无法处理 DnD ......我猜......所以我不得不添加一个 VM 参数:-Djdk.gtk.version=2,另外,如果要添加图像或其他任何内容,请添加此 VM 参数:-Dprism.forceGPU=true

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

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