Drag And Drop Example and Pointers

Hello,
Could you please point me to some code samples and URLs regarding the implementation of Drag and Drop in JavaFX?
(I want to implement a DnD between two TableViews)
Thx v much

I have done this and can give you some pointers. First see my bug report http://javafx-jira.kenai.com/browse/RT-14750 and you'll see they are working on Drag and Drop but here is how I did it.
First of all I attached event listeners to a custom row object provided with a row factory. The next thing I did was to create a DropTarget interface and a Draggable interface and a DragPane class. The drag mirror (DragPane) class is the node which will be dragged around the screen and is appended to the parent of your TableView's (assuming they share the same parent). The difficult part was detecting if I was over the drop target. I achieved that with the following code which is sitting inside the skin of a single control managing both the source and destination tables.
    public void onSourceRowDragged(MouseEvent event,CustomDraggableRow row)
        double sceneX = event.getSceneX();
        double sceneY = event.getSceneY();
        if (dragMirror == null) {
            dragMirror = new DragPane(row);
            // check for AnchorPane
            if (control.getParent().getClass().isAssignableFrom(AnchorPane.class)) {
                AnchorPane p = (AnchorPane)control.getParent();
                p.getChildren().add(dragMirror);
        javafx.scene.control.TablePosition p;
        // Locate drop target
        DropTarget nTarget = null;               
        Point2D tmpp = destTableContainer.sceneToLocal(sceneX,sceneY);
        Node overDestNode = destTableView.pickNode(tmpp.getX(),tmpp.getY());
        while(!(overDestNode == null || TableRowSkin.class.isAssignableFrom(overDestNode.getClass()))) {
            overDestNode = overDestNode.getParent();
            if (overDestNode == destTableView) {
                overDestNode = null;
        if (overDestNode != null) {
            TableRowSkin overSkin = (TableRowSkin)overDestNode;
            nTarget = (DropTarget)overSkin.getBehavior().getControl();
        if (dropTarget != null && dropTarget != nTarget) {
            dropTarget.onDraggableExited(event);
            dropTarget = null;
        if (nTarget != null && nTarget != dropTarget) {
            dropTarget = nTarget;
            dropTarget.onDraggableEntered(event);
    }This code really only works if the parent is a shared AnchorPane but it was the most difficult part of the project. As you can see the DragPane has a pointer back to the source, and when the mouse button is released if there is a dropTarget I notify the drop target that the object has been dropped. Lastly the mirror needs to be cleaned up. This technique is currently very slow, I suspect it is because the mouse events takes a long time to bubble up from the cells to the row object. I have plans of optimizing this by making the Row block mouse events from reaching the cells, but I haven't had time to optimize it yet. I also haven't followed the development teams official recommendation of creating an invisible cell over all of the other cells to capture the event because that solution, while possible, does not sound logical.

Similar Messages

  • Search drag and drop example

    I'm looking for a simple drag and drop example between two JList, what's the good way to do that....

    Try to start www.google.com
    enter "Drag Drop JList" and search i think the second is best:
    http://java.sun.com/docs/books/tutorial/dnd/sheetal.html
    sorry ;-) but you asked for a good way to look for a simple drag and drop example.

  • I would like to build a drag n drop interface and have the results sent to my email in PDF format. Is this possible?

    I would like to build a drag n drop interface and have the results sent to my email in PDF format. Is this possible?

    Captivate is not really designed to do what you want in this instance.  It's more targeted at allowing a user to complete an assessment and then track whether or not they passed.  So it's only really set up to send information in a format that the LMS will understand and interpret as Pass/Faill and what the score was.
    You really need something more flexible than that. So I think you would need to get a programmer involved and have the solution custom made.  In my experience, any time you try to diverge Captivate from what it was designed to do, and you need to get other IT professionals involved, you can kiss thousands of dollars goodbye before you have a workable solution.

  • Drag and Drop questions and Serialization in the 1Z0-852 Upgrade exam?

    Hi,
    Does anyone know if the drag and drop items and serialization have been removed from the 1Z0-852 Java SE 6 Programmer Certified Professional UPGRADE exam?
    I know that they have been removed from the 1Z0-851, but not sure about the upgrade exam.
    Thanks in advance,
    Alvaro

    Alvaro wrote:
    Hi,
    Does anyone know if the drag and drop items and serialization have been removed from the 1Z0-852 Java SE 6 Programmer Certified Professional UPGRADE exam?
    I know that they have been removed from the 1Z0-851, but not sure about the upgrade exam.
    Thanks in advance,
    Alvaro(1) Drag and Drop
    .... this question format will have been removed:
    Ref: http://blogs.oracle.com/certification/entry/0596
    (2) Serialization:
    It is best to compare the topics from your notes to the current topics, however according to my reading of the current topics it is in scope at least to some extent:
    http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=41&p_exam_id=1Z0_852 (Section 3 API Contents):
    Develop code that serializes and/or de-serializes objects using the following APIs from java.io: DataInputStream, DataOutputStream, FileInputStream, FileOutputStream, ObjectInputStream, ObjectOutputStream and Serializable.

  • Drag and drop examples do not work ?!

    Hi guys,
    i want to add drag and drop functionality to one of my programs
    i tried to run the java examples of this page:
    http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html
    but it just does not work ! windows give me the "can't drop" icon when i drag a file in the frame
    do you experience the same problem?
    Thanks in advance

    i tried:
    A Simple Example: Adding DnD to JLabel
    and
    Data Transfer with a Custom Component
    For both of these, i downloaded/compiled/executed the sourcecode ; there was no error. But the drop couldn't be done
    EDIT: in fact i just realised i didn't read the "try this" instructions and i misunderstood what the progs were supposed to do... in fact they work, they just don't do what i thought they would do XD
    sorry..
    EDIT2 I found a package for easy drag and drop operations ( http://iharder.sourceforge.net/current/java/filedrop/ ) so it's useless to answer to this thread any more, tks ^^

  • Really simple drag and drop example?

    I have just began exploring Adobe AIR and have succesfully
    managed to load images into an image component, through drag and
    drop from the desktop.
    Now I am trying to understand how to do the reverse —
    how to drag from the image component to the desktop, but after
    spending several hours googling I still haven't found an example
    that show how to achieve this. Either the samples are outdated,
    from the beta period, or to complicated for me to understand.
    Could someone please help me by showing how it is done, in
    the simplest possible way?
    Thanks in advance.

    Hi,
    You could let Christophe's excellent components do the heavy
    lifting for you:
    http://coenraets.org/blog/2007/06/air-to-desktop-drag-and-drop-two-simple-utility-classes/
    Or here's a good simple app with code that shows you how it's
    done:
    http://www.wabysabi.com/blog/2008/03/18/air-example-native-drag-n-drop-and-clipboard-integ ration/

  • Drag and Drop Examples?

    Are there any examples out there of an Edge Drag and Drop interaction? I need to create some drag and drop learning interactions in Edge and can't find any good examples.

    So I am at a loss again. I am taking what you made and trying to adapt it to what I need. However whenever I bring in an image instead of using a rectangle the drop part never works. So it works completly fine just as the rectangle but the image now does not. I want the person to drag the image over to the drop area and have it run code once dropped.
    Here is the link to what I have modified so far.
    https://www.dropbox.com/s/lpuv6mdmdi37vya/NewSlide.zip
    I think it may have to do with how it is referenced but not sure and could use some help.

  • Drag and drop, transferable and serializable

    I am currently writing a drag and drop algorithm for a JTree.
    I mostly follow the example at http://www.oreilly.com/catalog/jswing/chapter/dnd.beta.pdf
    now i encountered the following problem:
    If my Nodes are not serializable they are changed to null when a path containing them is returned via the getTransferData method as defined in the Transferable interface.
    If they implement Serializable I get a java.io.NotSerializableException:
    pointing at a class that has nothing to do with this whole operation other then being in the same package. If i also try to make this class serializeable i get java.io.NotSerializableException: that points to java.lang.ref.WeakReference (there are WeakReferences in the second class but they are totally independent to anything i try to drag and drop).
    Does anyone have any knowledge in that field?

    Had the same problems until we made the objects Cloneable also - adding a public Object clone() method to the class being Transferable-ized, making sure it obeyed clone() semantics, and we started getting the right data flavors.

  • Is it possible to make a graph with drag and drop plots and use it as a control?

    I am trying to make a graph with multippel plots to use as a control, the plots should be drag and drop. Is this possible in LV 7.0 or do i have to use c++ or WB?

    I second Doc-Doc comment. I am not sure what you are asking.
    The attached is an example I found on the NI web-site some time ago. I cannot find the link again so here is a ZIP of what I found in a temp folder on my machine.
    Trying to help,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    WF_SketchPad.ZIP ‏67 KB

  • Why Cant I Drag And Drop Music And Movies to My iPOD?

    Why does Apple make this so hard? I dont want to sync, everytime I do I lose everything and I dont like keeping a separate folder with my tunes I like to listen to all the time and then I dont have the time to go through 50 gig of music to uncheck or check what I want on my ipod.... Why cant I just drag and drop to my Ipod? Why do I need itunes is there another way to get music and videos on my ipod other than itunes?

    Also, I cant just look up what my ipod has on it all ready to delete some videos or music. It wants to sync up with my hard drive then it deletes everything.
    Sorry but I am way confused on this. I was really used to my basic MP3 player where I have folders on my drive that I just drag and drop/delete as easy as that.

  • HT2729 i have been trying to copy videos from my pc to ipad but it is not working .. i have tried the "drag and drop method and even add files to library but to no avail please help

    please help me regarding moving videos from pc to ipad .. i have ipad 2 wih ios5 and windows xp.. ihave tried add files to library and drag and drop method but they are not working.. what should i do

    Are you trying to add videos to itunes or to your ipad from itunes.
    Your question is very confusing.

  • Drag and drop interaction and restricted forward navigation

    I am using the Infosemantics widget in a captivate 6 project and it works well, but I have now been asked to restrict the forward navigation until the learner has completed the drag and drop and I can't work out how to do this as there isn't obviously anything I can assign an advanced action script to with the widget.  Any ideas how I can approach this - I don't want to have to code a drag and drop from scratch.

    Lieve is correct.  Anything you want to be executed as a result of the user's interaction with the widget needs to happen either via the On Success event, or the On Last Attempt (fail) event. 
    In the case of the Interactive Drag and Drop widget (as is also the case with all of our interactive widgets) you also have preference options that allow you to give the user multiple failure attempts by setting the preferences for Reset Success/Fail Criteria After Action.  If you want the timeline stopped while the user is working with the interaction you can also set the Disable Continue option so that the widget remains paused.

  • IWeb Podcast - Drag and Drop Audio and Picture Files

    I have been using iWeb the last few days to create a web site that includes some podcasts. I currently have three podcasts as a part of the site. I have been able to get two of the podcasts to work correctly but the third one, no matter how many times I recreate it seems to be where the difficulty lies.
    The podcast page gives me the opportunity to drag and drop an audio file and a picture file onto the page. As best I can tell, when I drop the audio file onto the page, things seem to be fine. When I drop the picture file onto the object, the audio clip seems to disappear. I have tried dropping the picture file first with basically the same results.
    A couple of more things. I created the original podcast file in GB3. I have found I can't import the podcasting file directly form GB because I end up with a very large file (>60GB) for the audio portion. So, I share the audio file to disk as an M4a file. When I add the audio to the podcast page in iWeb, I drag the audio file from Finder onto the object. The picture I have dropped onto the podcast page both from the Media Browser and from Finder. The results are the same.
    Any help is appreciated.
    Dave

    I think you're asking the question in the wrong forum. From what you posted, there's nothing wrong with GB, you should post in the iWeb forum where you're more likely to get useful and accurate answers about, well, iWeb.

  • Can't drag and drop apps and ringtones from itunes into the iphone.

    I'm sure it's something that I have to enable in itunes or the iphone, but I can't seem to drag and drop my apps or ringtones from itunes. This started when I got a replacement phone from my provider. I can't transfer them on my itunes. I get a block icon when I try to drag and drop. So the only way to get all the apps back is by re-downloading on the phone itself, but some apps are huge and I wouldn't want to do that. All the apps I backed up and even new ones I purchased can't seem to transfer. I tried deauthorizing and authorizing, re-downloading apps, syncing. So far nothing. Any tips?

    Thanks for trying but your answer is incorrect, according to an email I received today from HP Connected:
    "I have reviewed your email. I understand that you have questions related to rearranging the order of the apps on the printer. I know this can be frustrating, and I want you to know you're certainly valuable to us and I want to do everything possible to ensure your complete satisfaction. The following information should provide the answers you need:
    1) Unfortunately when HP launched the new website (www.hpconnected.com) they did not include a method of rearranging the apps on the printer. They may include this feature in a future update, however as this time it is not available.
    2) If you have made the upgrade from eprintcenter to HP Connected you do not have the option of returning. Eprintcenter is in the process of being eliminated and unfortunately retuning to the old site is not possible."
    I hope <<S-O-O-N>> HP fixes this new website -- it's crazy to take away any controls like this from their customers and not either embellish them or at least leave them be.
    I may take this 7610 OJ back for a new Brother 11x17 all-in-one --- they look nice )

  • Cannot drag-and-drop songs and playlists

    I just got a new 2nd Gen Nano on Saturday. iTunes 7.0.1.8 updated the Nano to software 1.0.2. It will sync songs and playlists when connected to the computer. However, if I want to manually add songs/playlists, it won't let me. I cannot drag and drop from my library to my iPod. Also, all the songs are greyed out on my iPod list and it will not let me drag and drop within my iPod. They only way it will let me update songs and playlists is with the automatic option.
    What is going on?

    The songs are "greyed out" because you have the iPod set to transfer songs automatically. That is also why the padlock icon appears at the bottom of iTunes next to the space used/available.
    If you want the songs to be bold and selectable/editable, then you need to change to manually managing your songs.

Maybe you are looking for

  • Java Heap Error when using Stateless Session Timer Bean deployed in Oracle

    Hi, Am getting following Java Heap Error when using Stateless Session Timer Bean deployed in Oracle 10g AS R3 (Oracle Containers for J2EE 10g (10.1.3.0.0) (build 060119.1546.05277) ): 06/08/02 14:58:43 javax.ejb.EJBException: java.lang.OutOfMemoryErr

  • Convert Row to Columns in Oracle

    i have table data like PHASE_NAME     SUB_PHASE_NAME     ACTIVITY_NAME     MANDATORY Pre Planting     Till/Cultivation     Environment Conditions     y Pre Planting     Till/Cultivation     Irrigation     n Pre Planting     Till/Cultivation     Soil

  • Problem with the graph when making DRILL DOWN

    Hello Hierarchy properties when I go to  graph And does DRILL DOWN At least once time, the graph gets stuck and when I change a parameter, a grapch is stuck Attached Link http://youtu.be/3kE3F_Vz2SQ Does anyone have an idea? BEST REGARD GADI

  • No eligible version of LOGIC found in applications folder to

    Have 7.0.1 insalled; trying to update to 7.1.1. Installer can't find an eligible version to update in apps. folder. Un-checking language in info section nets negitive results. Also put Logic folder on Desktop, then tried to update; no good. OS 10.3.9

  • Orchestrator security of Integration configuration accounts

    I have just installed Orchestrator 2012 R2 and I am planning to use the application to carry out several activities including general maintanance tasks as well as to control the Delegation of security permissions. I have 2 teams of people that are re