4 Replies Latest reply: Jul 9, 2012 12:56 PM by 921851 RSS

    drag and drop from JavaFX to native application

    teabeeoh
      Hi,

      in the Oracle tutorial on drag and drop support in JavaFX 2.X it says
      Moreover, drag-and-drop can be implemented between a JavaFX application and a third-party (native) application such as Windows Explorer or a desktop.
      It is documented how one can drag FROM a native application, e.g. the windows desktop to a JavaFX application, but I found no example drag and drop from a JavaFX application TO the native application. The use case would be for instance to drag data from the JavaFX application an drop it as a file on the windows desktop. Is this possible at all and if yes, can someone provide me a code example.

      Cheers

      Thomas
        • 1. Re: drag and drop from JavaFX to native application
          ytw
          Hello,

          Do you still have the link to the example of dragging from windows explorer into a JavaFx 2 app?
          Also, have you found a solution to your original problem (dragging from JavaFX app to native app)?
          I'm working on drag and drop as well.

          Thanks.
          • 2. Re: drag and drop from JavaFX to native application
            teabeeoh_
            Hi,

            well, everything you need for understanding drag & drop support from native to JavaFX is described here:
            http://docs.oracle.com/javafx/2/drag_drop/jfxpub-drag_drop.htm
            With that information you should be able to implement D&D in that direction. Concerning my actual problem, which is D&D from JavaFX to native, I neither found a solution nor support in the forum here. The question is still not answered.

            Cheers

            Thomas
            • 3. Re: drag and drop from JavaFX to native application
              twasyl
              Hi,

              I'm facing the same problem ... When a drag'n'drop a file from my Mac to my JFX app, the onDragDropped event isn't fired. I set up a Windows 7 64bits VM in order to test the app and it works.
              My code is the following:
               // ...
              @FXML
              public void dragOverHashtagTextField(DragEvent event) {
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                event.consume();
              }
                  
              @FXML
              public void dragEnteredHashtagTextField(DragEvent event) {
                this.hashtagTextField.setStyle("-fx-background-color: rgba(0,255,0,0.4);");
                event.consume();
              }
                  
              @FXML
              public void dragExitedHashtagTextField(DragEvent event) {
                this.hashtagTextField.setStyle("");
                event.consume();
              }
                  
              @FXML
              public void dragDroppedHashtagTextField(DragEvent event) {
                Dragboard dragBoard = event.getDragboard();
                boolean dragSuccess = false;
                System.out.println("Dropped 1");
              
                if(dragBoard.hasFiles()) {
                  System.out.println("Dropped 2");
                  dragSuccess = true;
                  BufferedReader reader = null;
                  String hashtag;
                          
                  for(File file : dragBoard.getFiles()) {
                    try {
                      System.out.println("Dropped 3");
                      reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8);
                      while((hashtag = reader.readLine()) != null) {
                        System.out.println("Dropped 4");
                        search(hashtag);
                      }
                    } catch (IOException ex) {
                      Logger.getLogger(TweetWallFXController.class.getName()).log(Level.SEVERE, null, ex);
                    } finally {
                      if(reader != null) {
                        try {
                          reader.close();
                        } catch (IOException ex) {
                          Logger.getLogger(TweetWallFXController.class.getName()).log(Level.SEVERE, null, ex);
                        }
                      }
                    }
                  }
              
                  event.setDropCompleted(dragSuccess);
                  event.consume();
                }
              }
              // ...
              I'm using JavaFX 2.1 with JDF 7u4b21 on OS X Lion 10.7.4

              Do you have any news?
              Thanks.
              • 4. Re: drag and drop from JavaFX to native application
                921851
                There's a bug report at JIRA concerning drag and drop from native to mac. It seems like the problem is not far from being solved. I encourage you to vote and watch the bug development.