JavaFX fire mouse release event after drag over

544
March 27, 2017, at 5:39 PM

I have a scene consisting of a single canvas. I'm tracking the mouse location and key presses. I've ran into a problem. After I drag the mouse over the control the mouse release event won't fire when I let go of the mouse button.

What I'm doing is making an image that's drawn onto the canvas graphics context follow my mouse when it's dragged. After I stop the drag and release the button the image should stop following the mouse. When I release the button the program still thinks the mouse is being held down because the mouse press tracker I have is in the mouse release even which isn't being fired.

Here is the relevant code. This is all my mouse event code.

canvas.setOnMouseMoved(new EventHandler<MouseEvent>() {
      @Override public void handle(MouseEvent event) {
                   mouse.lastLocation.set( event.getX() , event.getSceneY() );
                   event.consume();
      }
    });
        canvas.setOnDragDetected(new EventHandler<MouseEvent>() {
      @Override public void handle(MouseEvent event) {
          canvas.setCursor(Cursor.DEFAULT);
          Dragboard db = canvas.startDragAndDrop(TransferMode.ANY);
           /* Put a string on a dragboard */
          ClipboardContent content = new ClipboardContent();
          content.putString("test");
          db.setContent(content);
          //mouse.lastLocation.set( event.getX() , event.getSceneY() );
          canvas.startFullDrag();
          event.consume();

      }
    });
        canvas.setOnDragOver(new EventHandler<DragEvent>() {
      @Override public void handle(DragEvent event) {
          mouse.lastLocation.set( event.getX() , event.getSceneY() );
          event.consume();
      }
    });
        canvas.setOnScroll(new EventHandler() {
            @Override
            public void handle(Event event) {
               for (MouseKey key : mouse.getKeys()) {
                         if (key.getTrigger() == MouseKeyTrigger.WHEEL){
                             ScrollEvent evt = (ScrollEvent)event;
                             key.setDelta(evt.getDeltaY());
                             mouse.fireMouseWheel( evt.getDeltaX() , evt.getDeltaY() );
                         }
               }
               event.consume();
            }
    });
         canvas.setOnMousePressed(new EventHandler<MouseEvent>() {
      @Override public void handle(MouseEvent event) {
                for (MouseKey key : mouse.getKeys()){
                         if (event.getButton() ==  MouseButton.PRIMARY){
                             if (key.getTrigger() == MouseKeyTrigger.BUTTON1){
                                  key.triggered(true);
                             }
                         } else if (event.getButton() ==  MouseButton.SECONDARY){
                             if (key.getTrigger() == MouseKeyTrigger.BUTTON2){
                                  key.triggered(true);
                             }
                         } else if (event.getButton() ==  MouseButton.MIDDLE){
                             if (key.getTrigger() == MouseKeyTrigger.BUTTON3){
                                  key.triggered(true);
                             }
                         }
                  }
                event.consume();
      }
    });
         canvas.setOnMouseReleased(new EventHandler<MouseEvent>() {
      @Override public void handle(MouseEvent event) {
                    for (MouseKey key : mouse.getKeys()){
                         if (event.getButton() ==  MouseButton.PRIMARY){
                             if (key.getTrigger() == MouseKeyTrigger.BUTTON1){
                                  key.triggered(false);
                             }
                         } else if (event.getButton() ==  MouseButton.SECONDARY){
                             if (key.getTrigger() == MouseKeyTrigger.BUTTON2){
                                  key.triggered(false);
                             }
                         } else if (event.getButton() ==  MouseButton.MIDDLE){
                             if (key.getTrigger() == MouseKeyTrigger.BUTTON3){
                                  key.triggered(false);
                             }
                         }
                         event.consume();
                  }
      }
    });
READ ALSO
Reference and deep copy in java

Reference and deep copy in java

I have a question about the scenario of reference and deep copy in javaI have two codes below

403
javacc implementing a while in a parser

javacc implementing a while in a parser

I'm making a programming language and I'm in the middle of implementing a while loopIn my language while will work only comparing two values with <, > and <>

341
Calling a TypeScript callback method from Java file in Android APK [on hold]

Calling a TypeScript callback method from Java file in Android APK [on hold]

I am creating a hybrid Android application which uses Cordova and Angular 2I am trying to call a method inside TypeScript file from java method using webView

344
JNI Unsatisfied Link Error to C#

JNI Unsatisfied Link Error to C#

I have calling c# method in javaIt works in eclipse i

379