iiztp
iiztp

Reputation: 11

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. 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()"

Upvotes: 1

Views: 212

Answers (1)

iiztp
iiztp

Reputation: 11

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

Upvotes: 0

Related Questions