import java.awt.BorderLayout; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.event.EventHandler; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.input.ClipboardContent; import javafx.scene.input.Dragboard; import javafx.scene.input.MouseEvent; import javafx.scene.input.TransferMode; import javafx.scene.layout.VBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; public class App { JFrame frame; JFXPanel fxpanel; JFXPanel fxpanel2; public static void main( String[] args ) throws Exception { new App().init(); } private void init() throws Exception { fxpanel = new JFXPanel(); fxpanel2 = new JFXPanel(); // this panel doesn't need contents. It just needs to exist in the display hierarchy SwingUtilities.invokeAndWait(new Runnable() { public void run() { initSwing(); } }); Platform.runLater(new Runnable() { public void run() { initJavaFX(); } }); } private void initSwing() { frame = new JFrame("JavaFX Test"); frame.getContentPane().add(new JLabel("JFXPanel DnD exception..."), BorderLayout.NORTH); frame.getContentPane().add(fxpanel, BorderLayout.CENTER); // second JFXPanel is required to demonstrate bug - comment out the next line and the bug goes away frame.getContentPane().add(fxpanel2, BorderLayout.EAST); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(320, 240); frame.setVisible(true); } private void initJavaFX() { makeScene(); } private void makeScene() { Label label = new Label("Drag Me"); VBox box = new VBox(); box.getChildren().add(label); Scene scene = new Scene(box, 320,240); fxpanel.setScene(scene); label.setOnDragDetected(new EventHandler<MouseEvent>() { public void handle(MouseEvent t) { System.err.println("Drag detected"); Dragboard db = ((Node)t.getSource()).startDragAndDrop( TransferMode.COPY_OR_MOVE); ClipboardContent cc = new ClipboardContent(); cc.putString("Hello"); db.setContent(cc); t.consume(); } }); } }