Drag n Drop in JDK 1.4

I have a set of components that are enabled and disabled for DnD based on some criteria. Previously (in JDK 1.3), i would use that criteria to alternatively call acceptDrag(...) or rejectDrag() in the dragEnter and dragOver functions of each DnD component. This worked quite well as it altered the icon effectively as the user dragged an object over different components. However, in JDK 1.4, this seems not to work anymore.
Any ideas as to why or how to fix this?

i found the solution...apparently i had to set the cursor to null in the startDrag function to enable the automatic cursor handling.

Similar Messages

  • Drag and Drop fails with JDK 7u6 in Linux

    Hi,
    I'm face with a strange bug on JavaFX 2.2 (JDK 7u6, Ubuntu 12); I implemented drag & drop feature of labels in a stage; first time, I open the stage, the drag & drop works well; when I close the stage and reopen it, it fails : I can drag the label but I cannot drop it on the target (the target events are not fired); I can reproduce the bug easily with the class below, you have just to instantiate the class TestDragAndDrop in an application class.
    On window 7, it works well, I cannot reproduce the bug.
    Thank you for your help,
    David
    public class TestDragAndDrop {
        public TestDragAndDrop() {
            Stage stage = new Stage();
            stage.setTitle("Hello Drag And Drop");
            Group root = new Group();
            Scene scene = new Scene(root, 400, 200);
            scene.setFill(Color.LIGHTGREEN);
            final Text source = new Text(50, 100, "DRAG ME");
            source.setScaleX(2.0);
            source.setScaleY(2.0);
            final Text target = new Text(250, 100, "DROP HERE");
            target.setScaleX(2.0);
            target.setScaleY(2.0);
            source.setOnDragDetected(new EventHandler <MouseEvent>() {
                public void handle(MouseEvent event) {
                    /* drag was detected, start drag-and-drop gesture*/
                    System.out.println("onDragDetected");
                    /* allow any transfer mode */
                    Dragboard db = source.startDragAndDrop(TransferMode.ANY);
                    /* put a string on dragboard */
                    ClipboardContent content = new ClipboardContent();
                    content.putString(source.getText());
                    db.setContent(content);
                    event.consume();
            target.setOnDragOver(new EventHandler <DragEvent>() {
                public void handle(DragEvent event) {
                    /* data is dragged over the target */
                    System.out.println("onDragOver");
                    /* accept it only if it is  not dragged from the same node
                     * and if it has a string data */
                    if (event.getGestureSource() != target &&
                            event.getDragboard().hasString()) {
                        /* allow for both copying and moving, whatever user chooses */
                        event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                    event.consume();
            target.setOnDragEntered(new EventHandler <DragEvent>() {
                public void handle(DragEvent event) {
                    /* the drag-and-drop gesture entered the target */
                    System.out.println("onDragEntered");
                    /* show to the user that it is an actual gesture target */
                    if (event.getGestureSource() != target &&
                            event.getDragboard().hasString()) {
                        target.setFill(Color.GREEN);
                    event.consume();
            target.setOnDragExited(new EventHandler <DragEvent>() {
                public void handle(DragEvent event) {
                    /* mouse moved away, remove the graphical cues */
                    target.setFill(Color.BLACK);
                    event.consume();
            target.setOnDragDropped(new EventHandler <DragEvent>() {
                public void handle(DragEvent event) {
                    /* data dropped */
                    System.out.println("onDragDropped");
                    /* if there is a string data on dragboard, read it and use it */
                    Dragboard db = event.getDragboard();
                    boolean success = false;
                    if (db.hasString()) {
                        target.setText(db.getString());
                        success = true;
                    /* let the source know whether the string was successfully
                     * transferred and used */
                    event.setDropCompleted(success);
                    event.consume();
            source.setOnDragDone(new EventHandler <DragEvent>() {
                public void handle(DragEvent event) {
                    /* the drag-and-drop gesture ended */
                    System.out.println("onDragDone");
                    /* if the data was successfully moved, clear it */
                    if (event.getTransferMode() == TransferMode.MOVE) {
                        source.setText("");
                    event.consume();
            root.getChildren().add(source);
            root.getChildren().add(target);
            stage.setScene(scene);
            stage.show();
        public static void main(String[] args) {
            Application.launch(args);

    DUUUUUUUDE! IT'S WORKING NOW!!!!
    When you originally asked, "What happens if you click on an image and move it to another folder?", I didn't really understand what you were talking about because I almost never have my workspace set up in a way that the folders are showing. I always hide them. So I didn't really understand what you were saying. Just a few minutes ago, I realized that that is what you were asking so I opened up the folder area and tried dragging thumbs into different folders and saw that it does work.
    So then, because of you mentioning that blue line and me know that I did see the blue line on occasion. I went back over into the thumbnails to find out if I always got the blue line or if it was a hit or miss thing. I couldn't believe my eyes when all of the sudden I saw that I no longer was getting that circle with the line through it, and low and behold, the thumbnail dropped right into position like it is supposed to!!!!
    The thing is, I don't know what I've learned from this. I thought, "well, what is different?" The only thing that I can think of is that I now have the folders showing in my workspace so I wondered if that was the secret but I just now hid the folders again like I usually do and the drag and drop into position is STILL WORKING!!!
    All I can figure is that somehow, dragging and dropping a thumbnail into a folder like that for the first time, triggered something so that I can now drag and drop among the thumbnail positions? Not sure. All I know is that for some reason, IT'S WORKING NOW!
    Now, for the second important part, I wonder if I drag and drop everything into the order that I want and then select all of the files and drag them into a new folder, will they stay in that order? I need to go experiment with that.
    If you hadn't kept at it and in turn had me keep trying stuff, it would have never happened because I had pretty much given up.
    Thanks Curt!
    You da man!!!

  • Drag and Drop from a screen device (:0.0) to another (:0.1)

    Hello,
    Working with JDK 1.4 I have used the drag and drop in order to drag objects from a JFrame displayed in the logical screen :0.0 to another one, working in the same JVM, but displayed in the logical screen :0.1. This work fine.
    Now, I'm usin the JDK 1.5. With the same code, the drag operation does not work. During the drag operation, I can not move the mouse from one screen to another. The mouse is "blocked" in the source logical screen. The same code works with the JDK1.4 ? I have searched in the forum and I don't find any post on that subject ?
    The drag and drop is not compliant with the JDk 1.4 ? What can I do to resolve this problem ?
    Thanks you for yours answers !!
    Bruno

    I have change my drag and drop implementation. The old one uses the DragGestureListener. Now, I just use the TransfertHandler.
    The result in exactly the same : When the mouse reach the screen border, you can not move it to the other screen...
    Can someone try whith its application ?
    Have someone have a solution.... It is very important for my project.
    Thanks a lot !
    Bruno

  • Drag and Drop in a JTextArea (JTextPane)

    Hello everybody!
    I�ve a litte problem. I�m writing an online HTML-Editor as an Applet.
    Everything works fine, only drag&drop isn�t implemented yet.
    I�m using a JTextArea and a HTMLEditorKit in a SplitPane.
    Now i want to add drag&drop to each Pane. I need it urgent in the HTMLEdtiorKit , because it should be possible to drag and drop pics and text in the same pane.
    How can I add these feature ?!
    Maybe someone could write me a little example for a jTextArea oder a HTMLEditorKit ?!
    I�m actually using JDK.1.3.1, is there a big difference between 1.3.1 and 1.4 ?!
    Thanks,
    Ren�

    for those interested (if there is), i've given up on leadselectionpath, and i draw my outline manually, by overloading paintComponent and using the getPathBounds method.
    still, i don't know what leadselectionpath means... well, i guess i don't need to know, but if anyone want to share his knowledge...
    nicolas

  • Drag and drop images using tilelist in flex

    i just want the working code for drag and drop images using
    tilelist in flex

    Try JDK 1.4 and call setDragEnabled(true)
    I will also post updated version of MediaChest soon using custom TransferHandler for DnD different types of Objects.

  • Widget, Drag and Drop from palette not working.

    Hi All,
    I am trying to create a Widget using Eclipse and SAP Widget Tool.
    I was working on a simple widget creation from a custom widget template.
    The drag and drop option from palette doesn't work in my eclipse even after SAP widget tool has been installed.
    Please suggest.
    The configurations are.
    Eclipse - 3.4.2 ganymede
    Yahoo Widget Engine - 4.5.2
    jdk - 1.6.0_14 (latest one).
    Please help.

    I had to reinstall eclipse.

  • Drag and drop from/to JTable

    Hi,
    I am trying to implement drag and drop between two JTables. I have two questions about this and I hope you can help me.
    1. I would like to prevent the user from droping an Object in the same JTable as the object came from in the first place. How can I do that?
    2. How can I drop an Object in a JTable if there isn�t any rows in the table?
    I am using jdk 1.4.
    Thanks!!!
    :-)Lisa

    I think you just use setDragEnabled(true) on both tables.
    If not, then maybe this link will help:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html

  • 1.4 Drag and Drop - lost icons when added my own TransferHandler

    I've been trying to implement drag-and-drop using a custom TransferHandler on JDK 1.4.
    When I use the system default TransferHandler, I get nice icons that indicate whether the drop is allowed or not. Once I implemented my own TransferHandler, all I get is a dim grey outline when I drag -- the icon doesn't change when I drag to an area where acceptDrag() is being called versus one where rejectDrag() is being called. (I've got println's in the code so I can verify the accept/reject calls are happening, but the icon never changes).
    It would be extra nice if the icon indicated whether a COPY or MOVE operation was selected, and toggled the icon appropriately.
    From other messages in this forum, it appears that the getVisualRepresentation() method of TransferHandler is never called, so that would not help.
    I don't really need customized behavior here; I'm just trying to get back the behavior I saw with the default TransferHandler. Any suggestions?
    Thanks!
    Mike Yawn

    I've been trying to implement drag-and-drop using a custom TransferHandler on JDK 1.4.
    When I use the system default TransferHandler, I get nice icons that indicate whether the drop is allowed or not. Once I implemented my own TransferHandler, all I get is a dim grey outline when I drag -- the icon doesn't change when I drag to an area where acceptDrag() is being called versus one where rejectDrag() is being called. (I've got println's in the code so I can verify the accept/reject calls are happening, but the icon never changes).
    It would be extra nice if the icon indicated whether a COPY or MOVE operation was selected, and toggled the icon appropriately.
    From other messages in this forum, it appears that the getVisualRepresentation() method of TransferHandler is never called, so that would not help.
    I don't really need customized behavior here; I'm just trying to get back the behavior I saw with the default TransferHandler. Any suggestions?
    Thanks!
    Mike Yawn

  • Drag and drop problem from wizard inside another drop

    I am using JDK 1.5.0_11 Swing.
    I am facing a Drag and Drop problem which is described below:
    A drag and drop operation invokes a wizard, from which another wizard is invoked. Within one of the panels of this 2nd wizard, I am trying to do a drag and drop from a JTextarea to a JTree node, but am NOT able to. I am not getting any exceptions. I have written a transfer handler for the JTree node to handle the text transfers from a JTextArea. When I try to do a drag and drop from a JTree node to another JTree node I'm getting the 'InvalidDNDOperation: drag and drop in progress' exception.
    When the 2nd wizard is invoked directly, I am able to do the drag and drop from JTextArea to a JTree node and also from a JTree node to another JTree node.
    I tried spawning a new thread for the 2nd wizard, but am still unable to initiate drag and drop.
    Should I be spawning a new thread for the 1st wizard?
    Message was edited by:
    sbandyop

    Please post Swing questions in the Swing forum: http://forum.java.sun.com/forum.jspa?forumID=57

  • Drag and Drop between JTree and another component

    Hi,
    I have searched the forum for answer to this question but am not sure I found something similar to this. So, please help me out on this.
    I have a JTree and a JPanel, which basically shows images (as thumbnails) for the child nodes of one node in the tree heirarchy.
    I need to be able to drag and drop components from the JPanel to the JTree and vice versa, and of course, when you drop them on the tree, they should go under the correct node.
    I am using Swing 1.4.1, and have successfully implemented DnD in the JTree itself. But I am a little unclear about the DnD between the tree and the panel.
    Would really appreciate if someone could throw some light on this.
    Thanks a lot,
    Sri.

    Hi clairesheridan,
    thanks for your response. Your answer would have helped me if I was using JDK 1.3 but I am try to use the Swing API in jdk1.4.1, in which you have to set a transferhandler etc.
    Please let me know if you have any ideas or solutions.
    Thanks,
    sriharmya.

  • Drag and Drop between JTree and Labels in 2 different panes

    Hi,
    I am using JDK 1.4.1 and am trying to implement Drag n Drop between a JTree and JLabels with ImageIcons, both on different panes.
    I got the DnD working fine on the tree. but i cant get to drag and drop the label from the other pane, on the Jtree as a node. I am getting confused with the DataFlavors, and also wonder if there is something else that i have to do for DnD between 2 panes. Can someone give me any leads on this, please? The Panes I am talking about are splitpanes.
    thanks,
    Sri.

    hey thanks Dennis!! I was hoping you would respond to my question, as I have seen a lot of your replies. yes, the example you gave would be helpful. but i am trying to implement this in 1.4.1, with the new drag and drop in swing. and i am getting confused wiht theh data flavors etc.
    my problem at hand is :
    I have a tree on the left pane. i can drag and drop the nodes on the tree itself. (i already did that...no problem). I have Jlabels with imageicons (actually wrapper classes with labels and imageicons) on the right pane. i have to be able to drag these labels to the tree such that they form a node.
    I have one class the NodeSelection class which extends TransferHandler and implements Transferable. i was able to do DnD for the tree using this. I customized the importData method in this.I thought that i can just use the same class to create the transferhandler and transferable, and just use a different implementation for the importData method if the data being dragged is from the label.
    well, my thoughts and ideas were ok...but i can implement it...so they must be wrong ;-)
    Can u please suggest another way to do this. I have a deadline to meet and am stuck here :-( any suggestions or tips or hints would be very helpful and appreciated!!
    Thanks,
    Sri.

  • Drag and Drop between 2 Panes

    Hi,
    I am using JDK 1.4.1 and am trying to implement Drag n Drop between a JTree and Labels with ImageIcons, both on different panes.
    I got the DnD working just on the tree. but i cant get to drag and drop the label on the Jtree as a node. I am getting confused with the DataFlavors, and also wonder if there is something else that i have to do for DnD between 2 panes. Can someone give me any leads on this, please?
    thanks,
    Sri.

    hey thanks Dennis!! I was hoping you would respond to my question, as I have seen a lot of your replies. yes, the example you gave would be helpful. but i am trying to implement this in 1.4.1, with the new drag and drop in swing. and i am getting confused wiht theh data flavors etc.
    my problem at hand is :
    I have a tree on the left pane. i can drag and drop the nodes on the tree itself. (i already did that...no problem). I have Jlabels with imageicons (actually wrapper classes with labels and imageicons) on the right pane. i have to be able to drag these labels to the tree such that they form a node.
    I have one class the NodeSelection class which extends TransferHandler and implements Transferable. i was able to do DnD for the tree using this. I customized the importData method in this.I thought that i can just use the same class to create the transferhandler and transferable, and just use a different implementation for the importData method if the data being dragged is from the label.
    well, my thoughts and ideas were ok...but i can implement it...so they must be wrong ;-)
    Can u please suggest another way to do this. I have a deadline to meet and am stuck here :-( any suggestions or tips or hints would be very helpful and appreciated!!
    Thanks,
    Sri.

  • Drag and Drop - Help Plz!

    I am doing a project that involves Drag and Drop with JLabels.
    What i want to do is:
    When the draggable is dropped onto the droppable JLabel, I want to update the position of the draggable. So far, when i try to update the position of the dragged JLabel, i seem to update the Droppable JLabel's position. Is there a way to reference both draggable and droppable JLabels inside the drag method?
    here is the part of my code that updates the wrong position:
    /* from class CardImage extends JLabel implements (Drag and Drop listeners) */
    public void drop (DropTargetDropEvent event) {
    DropTarget targ = (DropTarget)(event.getSource());
    Component source = (JComponent)(targ.getComponent());
              if ((event.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0)
                   event.acceptDrop(event.getDropAction());
                   event.getDropTargetContext().dropComplete(true);
                   double x = event.getLocation().getX(); // this bit updates the position
                   double y = event.getLocation().getY()+20; // slightly below the drop position but still on top of it
                   this.setLocation((int)x,(int)y); // "this" refers to a JLabel which uses an ImageIcon
                   this.setVisible(true);
              else
                   event.rejectDrop();
    }

    hi friends,
    please help me , i m trying to drag and drop a jlabel inside a panel. i m trying to do it using MouseListener. but problem is that i m not getting axact position of mouse releasing. JLabel is getting set randomly at its own position.(i m using JDk 1.3)
    please help me, i have already invested a lot of time in this.
    thanx in advance.

  • JTree Drag and Drop question

    I have drag and drop working fairly well using jdk 1.4. I'm able to copy and move objects around in the tree and change the cursor as it moves over various objects in the tree. The only problem I'm having is when the user drops something into someplace that rejects the drop, for instance in the blank area of the JTree object. In this case, the drop never seems to complete. If I try to drag that same object again it throws an InvalidDnDOperationException saying that a DnD operation is already in progress. I noticed that the drop() operation is not being called when the user drops the object into a rejected area.
    I've searched the forums and haven't seen anyone else report this problem. Does anyone have any suggestions?

    I'd love it too if you would send me you code, or post it so others can benefit; there seems to be quite a number of people who want DnD JTree functionality. I've been going nuts trying to figure out the best way to implement DnD on a JTree. I started using the new TransferHandler and had reasonable success with it. But, I'm not sure how to get the cursor to change based on DropTarget (not all nodes are created equal in this regard). I need access to the DragSourceContext, but I don't know how to get it when using the TransferHandler method.
    I have other issues with the TransferHandler also, like trying to make DnD work consistently with Cut-And-Paste all in the same TransferHandler. Or, trying to deal with the fact that you can change a move-type DnD operation into a copy-type operation after you start dragging, but before you drop just by pressing the control-key. This sort of implies to me that the original createTransferable() should always make a copy, so that the only issue is whether to clean up in exportDone().

  • Do I need to have data before performing Drag and Drop????

    I have gotten drag and drop working with Swing in JDK 1.4b2 using "URL-based" files instead of operating system native files. The way this was accomplished by creating a wrapper class that sub-classed File and would download the contents of the URL to a temporary file and then initiate a normal drag and drop operation using the normal java file mechanisms. However, when you have a large file, the operation can take too long since I am fronting all of the effort at the start of the drag. I would like to be able to delay the need to produce the bytes/files to give to the operating system until after there has been a successful drop, at which point I can do the heavy lifting and raise a dialog telling them that the action is commencing. As best as I can tell, you must have all of the data BEFORE any operation (which could be a potential design flaw!!)
    So, is there a way to get a hook that there has been a successful drop to a vm-external drop target before the VM gives the data over? Even if I create my own data flavor (which isn't well documented outside of Text types) won't I still run into the same problems? Am I just overlooking something simple?
    Thanks for your help.

    Hello
    I've had the same problem, but take a look at: http://foxtrot.sourceforge.net/
    You can use their API to start the long consuming time job (reading files from the network) and also to paint a progress bar, showing the progress in the Event Dispatch Thread.
    This is how I've solved my problem:
    I've passed a MyTransferable object to the startDrag method of the DragGestureEvent event.
    In the getTransferData method of MyTransferable object (that implements Transferable interface) I've used the Worker.post method of their API which reads the file from the network and updates a progress bar.
    The API lets the Event Dispatch Thread enter but not return from the listener method (getTransferData in my case), instead rerouting the Event Dispatch Thread to continue dequeuing events from the Event Queue and processing them (repaint the progress bar). Once the worker thread has finished, the Event Dispatch Thread is rerouted again, returning from the listener method.

Maybe you are looking for