Lexxicon

Standalone FX dnd

Sep 3rd, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package fxtest;
  2.  
  3. import java.io.BufferedOutputStream;
  4. import java.nio.ByteBuffer;
  5. import java.util.Arrays;
  6.  
  7. import javafx.application.Application;
  8. import javafx.event.EventHandler;
  9. import javafx.scene.Scene;
  10. import javafx.scene.input.ClipboardContent;
  11. import javafx.scene.input.DataFormat;
  12. import javafx.scene.input.DragEvent;
  13. import javafx.scene.input.Dragboard;
  14. import javafx.scene.input.MouseEvent;
  15. import javafx.scene.input.TransferMode;
  16. import javafx.scene.layout.Pane;
  17. import javafx.stage.Stage;
  18.  
  19. public class App extends Application {
  20.     DataFormat refTrans = new DataFormat("MyDraggable");
  21.     public static void main(String[] args) {
  22.         launch(args);
  23.     }
  24.    
  25.     @Override
  26.     public void start(Stage primaryStage) throws Exception {
  27.         final Pane pane = new Pane();
  28.         pane.setOnDragDetected(new EventHandler<MouseEvent>() {
  29.  
  30.             @Override
  31.             public void handle(MouseEvent event) {
  32.             Dragboard db = pane.startDragAndDrop(TransferMode.COPY_OR_MOVE);
  33.                 ClipboardContent content = new ClipboardContent();
  34.                 BufferedOutputStream o = null;
  35.                 content.put(refTrans, "FromFX");
  36.                 db.setContent(content);
  37.                
  38.                 event.consume();
  39.             }
  40.         });
  41.         pane.setOnDragEntered(new EventHandler<DragEvent>() {
  42.  
  43.             @Override
  44.             public void handle(DragEvent event) {
  45.                 System.out.println("DragEntered");
  46.                 for(DataFormat df : event.getDragboard().getContentTypes()){
  47.                     System.out.println(df.equals(refTrans));
  48.                 }
  49.                
  50.             }
  51.         });
  52.         Scene scene = new Scene(pane, 800, 600);
  53.         primaryStage.setScene(scene);
  54.         primaryStage.show();
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment