Using DragEvents between different JFXPanels

Hi. I'm trying to set up a drag-and-drop function in my application that should transfer some data on a successful drag-and-drop completion. I'm following the examples given here:
Drag-and-Drop Feature in JavaFX Applications | JavaFX 2 Tutorials and Documentation
The event handler code for my source and target objects are exact copies of the source.setOnDragDetected and target.setOnDragOver / target.setOnDragDropped provided in the above example. I am putting a simple String into the DragBoard with a call to putString on the source event handler.
The drag and drop is initiated successfully (source event handler fires and puts the text in the DragBoard as per the example), but upon receving the DragEvent in the target event handler, it is not the same DragBoard - this one is simply empty. A call to DragBoard.getString() on the target DragEvent returns null.
The example works fine, with exactly the same code - line for line. What is different in my application is that both the source and the target nodes exist within separate JFXPanels. I have confirmed that both event handlers fire on the same thread, so it is not a threading issue either.
I'm drawing a blank here and am starting to think that embedding the scene in a JFXPanel somehow screws up the drag and drop data transfer via DragBoard. Can anybody clarify a bit around this issue for me? Thanks.

Just running some simple tests, the different JFXPanels do indeed appear to have different dragboards. One workaround is to use a JavaFX Property (or some other mutable wrapper for your data) to store the value being dragged.
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DragEvent;
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.JPanel;
import javax.swing.SwingUtilities;
public class JFXPanelDnD {
    private final StringProperty draggingContent ;
    public JFXPanelDnD() {
        draggingContent = new SimpleStringProperty();
    private void initAndShowGUI() {
        // Execute on EDT thread
        final JFrame frame = new JFrame("DnD Between JFX Panels");
        final JFXPanel leftPanel = new JFXPanel();
        final JFXPanel rightPanel = new JFXPanel();
        final JPanel panel = new JPanel();
        panel.add(leftPanel);
        panel.add(rightPanel);
        frame.add(panel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(420, 320);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        Platform.runLater(new Runnable() {
           @Override
           public void run() {
               configureLeftPanel(leftPanel);
               configureRightPanel(rightPanel);
    private void configureLeftPanel(JFXPanel panel) {
        // Execute on JavaFX Application thread
        final TextField textField = new TextField();
        final VBox root = new VBox();
        root.setOnDragDetected(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                System.out.println("Drag detected");
                Dragboard db = root.startDragAndDrop(TransferMode.ANY);
                System.out.println(db);
                ClipboardContent content = new ClipboardContent();
                content.putString(textField.getText());
                db.setContent(content);
                draggingContent.set(textField.getText());
                event.consume();
        root.setOnDragDone(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
                draggingContent.set(null);
        root.getChildren().add(textField);
        Scene scene = new Scene(root, 200, 300);
        panel.setScene(scene);
    private void configureRightPanel(JFXPanel panel) {
        final Label label = new Label("Text");
        final VBox root = new VBox();
        root.setOnDragOver(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
                final Dragboard dragboard = event.getDragboard();
                System.out.println(dragboard);
//                if (dragboard.hasString()) {
//                    event.acceptTransferModes(TransferMode.COPY);
//                } else {
//                    System.out.println("No string content");
                if (draggingContent.get() != null) {
                    event.acceptTransferModes(TransferMode.COPY);
        root.setOnDragDropped(new EventHandler<DragEvent>(){
            @Override
            public void handle(DragEvent event) {
//                Dragboard db = event.getDragboard() ;
//                if (db.hasString()) {
//                    label.setText(db.getString());
//                    event.setDropCompleted(true);
//                } else {
//                    event.setDropCompleted(false);
                if (draggingContent.get()==null) {
                    event.setDropCompleted(false);
                } else {
                    label.setText(draggingContent.get());
                    event.setDropCompleted(true);
                event.consume();
        root.getChildren().add(label);
        Scene scene = new Scene(root, 200, 300);
        panel.setScene(scene);
    public static void main(String[] args) {
        final JFXPanelDnD test = new JFXPanelDnD();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                test.initAndShowGUI();

Similar Messages

  • HT3819 How to use homesharing between different user accounts on the same iMac?

    I find plenty of articles about homesharing on iTunes between computers, but not between two different user accounts on the same iMac.  Any advice or direction to an existing artical is greatly appreciated.  I'm knew to the Mac and still have Windows on the brain.
    I am trying to share iTunes music and movie purchases between my user login and my wife's.
    Thanks

    Hello careymp1017,
    This can be achieved, but will not utilize HomeSharing. Further information and steps can be found in the following article.
    iTunes: How to share music between different accounts on a single computer
    http://support.apple.com/kb/HT1203
    Cheers,
    Allen

  • Transfer files using wifi between different OS.

    How to transfer files e.g. doc; xls or any files using wifi between ios and android devices ?

    Check out the Feem WiFi File Transfer app
    https://itunes.apple.com/us/app/feem-wifi-file-transfer-free/id596378699?mt=8
     Cheers, Tom

  • HT1203 iTunes: How to share music between different accounts on a single computer - I tried to use the instructions to configure 2 different windows users sharing the same iTunes library.  I could not get this to work per the instructions.

    I tried to configure 2 windows users accounts using a single library per the instructions in HT1203.  My iTunes library is on an external drive.  I cannot get this to work.  Any suggestions?

    To give other users read-only access to your iTunes library, use the Sharing features of iTunes. Sharing works over the local network as well as on the same computer. See the built-in help for details.
    If you want to give full read/write access to more than one user, see the support article linked below.
    iTunes: How to share music between different accounts on a single computer
    There is a way to share the library without moving it to a secondary volume. If you really need to do that, ask for instructions.

  • How can you use iMessage between 3 iPads with 3 different users but only one Apple ID?

    how can you use iMessage between 3 iPads with 3 different users but only one Apple ID?

    No you do not need separate Apple ID's in order to use 3 devices with one Apple ID. I use 4 devices to Message and FaceTime and all use the same Apple ID. You do need to add additional email addresses for the other devices.
    Look at this very informative video for the instructions.
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l

  • How can I use DOM to copy Nodes between different XML Document ?

    Can I copy one Node or Element from one XML Document to another Document by DOM ?
    Because I use the Xerces , but it is not work if I want to copy Node between different Document, or I am doing something wrong. Anyone can help me , I will deeply appreciated !!

    check out the importNode() method of Document.

  • Using XML to exchange data between different databases?

    Hi,
    Does anyone know of any case-studies or tutorial's where XML has been used to transfer data between different databases... i.e. oracle to sql server?
    I basically looking into the differences between two schema's and what sort of tranformations need to take place.
    Thanks in advance guys!

    Hi,
    Does anyone know of any case-studies or tutorial's where XML has been used to transfer data between different databases... i.e. oracle to sql server?
    I basically looking into the differences between two schema's and what sort of tranformations need to take place.
    Thanks in advance guys!

  • Is there any way to stop the delay between different sets of speakers when using airport express?

    Is there any way to stop the delay between different sets of speakers when using airport express?

    Unfortunately, I don't have either a Slingbox or iHome speakers so I won't be able to reproduce any of the issues you are having. With the fact that you live in large apartment complex would still lead me to believe that Wi-Fi interference may be the reason that you are having streaming issues.
    I suggest you perform a simple site survey, using utilities like iStumbler, or AirRadar to determine potential areas of interference, and then, try to either eliminate or significantly reduce them where possible.

  • How to use 'UNION' between two different databaseservers

    Hello,
    Could someone help me out. I am trying to find out if and how to use 'UNION' between two different databaseservers.
    We have 2 different queries, each queries on a different database; one MySQL the other MSSQL.
    Could someone tell me how to use 'UNION' between thes 2 queries?
    Thanks in advance,
    Samir Benalla

    Hello
    You may use openrowset statement, (OPENROWSET (Transact-SQL))., but before you use this, you must configure your server
    sample:
    SELECT a.*
    FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;',
         'SELECT GroupName, Name, DepartmentID
          FROM AdventureWorks2012.HumanResources.Department
          ORDER BY GroupName, Name') AS a
    UNION
         SELECT GroupName, Name, DepartmentID
          FROM AdventureWorks2012.HumanResources.Department
          ORDER BY GroupName, Name
    With this you can define a connection using native client to server Seattle1, and execute a query there, The results will be spooled on your server.
    Connectionstring
    Server=[SERVER_NAME];datasource=[YOUR DATABASE NAME];user_id=sa;password=sapassword'
    if you use FQDN on your Query, than the datasource parameter in connection string can be letf out.
    Regards
    János.
    take care of performance, it can be very slow,

  • How can I sync/import/export bookmarks between different users on the same computer and both using the Firefox browser?

    All help instructions are for importing or exporting bookmarks/favourites between different brands of browsers.

    Many thanks twalker for your prompt and simplified explanation for resolving my problem which is much appreciated by this tarnished silver surfer. I will now arrange to download FX4 and follow your instructions.

  • Context binding between different components using component interface cont

    Please tell me the procedure how to do context mapping between different components ......
    Please post the procedure ASAP.

    Hi Koti,
               Check this
    <a href="/people/bertram.ganz/blog/2007/01/19/new-web-dynpro-java-tutorial--component-interface-definitions-in-practice:///people/bertram.ganz/blog/2007/01/19/new-web-dynpro-java-tutorial--component-interface-definitions-in-practice
    <a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/wdjava/usecomponentsinbiggerWebDynproprojects%28componentization%29&">https://www.sdn.sap.com/irj/sdn/wiki?path=/display/wdjava/usecomponentsinbiggerWebDynproprojects%28componentization%29&</a>
    regards
    Sumit

  • Sharing songs between different iTunes accounts on the same Mac

    Hello
    I am a newbie to Mac. My wife and I both have seperate iTunes accounts set up on our seperate user accounts on our MacBook. Can we share songs between our accounts?

    *BA Mack* wrote:
    Can we share songs between our accounts?
    Zevoneer wrote:
    You might find this article useful: iTunes: How to share music between different accounts on a single computer
    The process for sharing libraries is much [easier in iTunes 8|http://forums.macworld.com/thread/105366?tstart=0]. If you simply want to share a few songs, you are better off having a copy of those tracks in each of your libraries, but there is little point to that as you can access each other’s libraries in read-only fashion.

  • Can I put my library on an external hard drive and use it between two computers?

    Can I put my library on an external hard drive and use it between two computers? I have two MBP; I will refer to one as computer A and to the other as computer B. I would like to be able to plug in my external hard drive, boot up iTunes, and if there were any changes made to the library previous to its last time accessed on this compluter, they show up on that computer, regardless of being imported on the other.
    A hypothetical example: I import three albums called 1, 2, and 3 on computer A over a week or so. I take the external hard drive and plug it into computer B. The entire library which was visible on A, is visible on B, including albums 1, 2, and 3.
    Is this possible? If so, what files need to be copied onto the external? I'm trying some different combinations, trial and error basically. Hopefully someone knows and can answer before I mess up my library. I also want to do this to free up space on my computer. All importing will be done from disc.

    iTunes/Preferences/Advanced : point your iTunes to the new location of the Library.
    Set "Share on local network" in the Sharing tab, and you or everyone on the local network can play your music.
    You make a backup first of the Library.
    Move the follwing to the new location:
    /Users/your username/Music/iTunes/iTunes Music
    have fun.

  • Sharing iphoto library on the same computer between different users

    Can anyone tell me how (without having to write my own code) I can share photos easily (so I can teach my parents, who know nothing about mac, how to do it) between different users on the SAME COMPUTER?
    I am so frustrated! You can share with anyone else in the world, but when it is on the same computer I can't figure out how to share!

    Hi Mereditty,
    Here are all the links I have for sharing a couple of different ways.
    SHARING IPHOTO LIBRARIES
    Sharing libraries between users on the same local network
    You can also share a library on the same machine between users the same way.
    Sharing libraries between users on the same machine...
    -both users must have sharing enabled in their iPhoto Preferences
    -both users must be logged in and have iPhoto running
    -Remember that you can only view the other library. You can't edit the photos or play the saved slideshows or view the made books or burn them to CD or DVD. The books and slideshows will show up as an album. You can play that album as an "on the fly" slideshow. You can drag images from the sharing library to your library in the source column to import them to your library. You can then edit, add to albums, books, slideshow, etc.
    Sharing links from Apple....
    Sharing your photos between computers
    About shared photos
    Turning off photo sharing
    Looking for shared photos
    SHARING ONE IPHOTO LIBRARY BETWEEN USERS ON SAME MACHINE
    You can try one of these three methods:
    1- Use iPhoto Library Manager-the paid version
    The documentation page will give instructions on how it is done.
    2- Sharing one iPhoto library between several users on one machine
    3- Share an iPhoto Library in tiger Using ACL's
    4- I have also read about ShareAlike
    There is no other info on the site about how it works.
    I strongly urge anyone wanting to try any of the methods for sharing one iPhoto Library folder among more than one user to backup all iPhoto Library folders before attemptin anything.
    Lori

  • How do I share photos and music between different user accounts on the same macbook

    How do I share photos and music between different user accounts on the same Macbook? i.e. I want all to be able to access family photos when logged into their respective accounts. Same goes for the iTunes library. Hope this is possible...
    Thanks!

    To give other users read-only access to your iTunes library, use the Sharing features of iTunes. Sharing works over the local network as well as on the same computer. See the built-in help for details.
    To give others selective access to your iPhoto library, you have the option of using iCloud Photo Sharing, if the privacy implications don't bother you. The images will be stored temporarily on Apple servers.
    If you want to give full read/write access to more than one user, see the support articles linked below.
    iTunes: How to share music between different accounts on a single computer
    iPhoto: Sharing libraries among multiple users
    There is a way to share the library without moving it to a secondary volume. If you really need to do that, ask for instructions.

Maybe you are looking for

  • Urgent: Issue with variable exit

    Hi All, We are having a requirement where in we need to populate the value of calday as the first day of the month that the user selects in the variable. For that, this is what i did: 1. Created a variable for 0CALDAY as ZDAT1 and made it as "Process

  • Oracle Forms and Portal. & Portal Security

    I need the following questions answered for a client who is trying to move from IIS to Oracle Portal. any pointers would be extremely helpful 1. How to configure Oracle Forms to run with Portal. 2. Is it possible to display forms inside a Portlet. If

  • Can I purchase a power adapter for the Iphone 5 at a retail store????

    Can i purchase a power adapter for the iphone 5 at an apple store??? Mine was stolen from my car ------ arrrrrggggghhhhhhhhhhh

  • Errors on plxmlparser v102 installation

    The loadjava part of plxmlparser (v 1.02) was not quite a success, with a total of 227 errors ! The first errors were of type: ORA-29534 eg: XMLBytereader could not be resolved (very first error) The following ones were showing this kind of messages:

  • Zen NX Problem

    I have a Creative Nomad Jukebox Zen NX (running XP SP, if that makes any difference), and I just reinstalled the software (all of it, because my computer was not detecting the mp3 player). I try to open CMS Organizer, but i get a message saying: This