Drag and Drop Tutorial  -- Most Requested

Tutorial for one of the most reqeusted questions made! how to make drag and drop in Adobe Edge Animate , Check it out : http://www.edgehero.com/tutorials/draganddrop

[url http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html]Introduction to Drag and Drop

Similar Messages

  • Recommend me a good drag and drop tutorial

    I need to make a movie whereby the user drags four items onto 4 targets and achieves a result as each object lands on the target, such as a sound. and then a well done statement at the end.
    Can anyone recommend me a place where I can download such a file so I can manipulate it? I figured an hour ago when i sat at my computer that I would find one easily, but I'm really stuck now. can anyone suggest a tutorial/ site where I could get a free download of an advanced drag and drop like this?
    I'd really appreciate your help!
    Thanks.
    Niamh.

    These are the 2 good tutorials that helped me in making Drag and Drop in flash : http://www.flashvalley.com/fv_tutorials/advanced_drag_and_drop_in_Flash/
    http://www.actionscript.org/resources/articles/26/1/Drag-n-Drop-and-Drop-Targets/Page1.htm l
    Thanks,
    Sudheendra

  • Drag and Drop Between two Panels

    Hi,
    I am working with Swings,i created two Panels A and B. I kept some GIF or Image in Panel A,i would like to drag the gif object in to Panel B.
    when i try like this,my mouse could not communicate with two panels A and B.mouse events working Individualey,i mean mouse events working in same panel.
    Plz let me know how to communicate with two different panels with mouse. Drag and Drop between Panel A and Panel B.
    Thanking you
    MyProblems

    You might check out the Drag and Drop tutorial, especially the section Data Transfer with a Custom Component.
    Here's another approach using an overlayed non–opaque JPanel as a transfer device. The image label is transfered to the (fake) glass pane and dragged. On mouse release it is added to the JPanel below. Although I didn't build in any boundry–checking it would be a useful thing. Mostly to ensure a suitable drop target and component location in it.
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DraggingTest
        public static void main(String[] args)
            LeftPanel left = new LeftPanel();
            JPanel right = new JPanel();
            right.setBackground(new Color(200,240,220));
            right.setLayout(null);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.fill = gbc.BOTH;
            panel.add(left, gbc);
            panel.add(right, gbc);
            JPanel glassPanel = new JPanel();
            glassPanel.setOpaque(false);
            JPanel overlay = new JPanel();
            OverlayLayout layout = new OverlayLayout(overlay);
            overlay.setLayout(layout);
            overlay.add(glassPanel);
            overlay.add(panel);
            ImageMover mover = new ImageMover(left, right, glassPanel);
            glassPanel.addMouseListener(mover);
            glassPanel.addMouseMotionListener(mover);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(overlay);
            f.setSize(400,400);
            f.setLocation(600,325);
            f.setVisible(true);
    class LeftPanel extends JPanel
        Image image;
        JLabel label;
        public LeftPanel()
            loadImage();
            setBackground(Color.white);
            setLayout(null);
            label = new JLabel(new ImageIcon(image));
            label.setName("imageLabel");
            Dimension d = label.getPreferredSize();
            label.setBounds(40, 40, d.width, d.height);
            add(label);
        private void loadImage()
            String fileName = "images/dukeWaveRed.gif";
            try
                URL url = getClass().getResource(fileName);
                image = ImageIO.read(url);
            catch(MalformedURLException mue)
                System.out.println(mue.getMessage());
            catch(IOException ioe)
                System.out.println(ioe.getMessage());
    class ImageMover extends MouseInputAdapter
        LeftPanel left;
        JPanel right, glassPanel;
        JPanel activePanel;
        Component selectedComponent;  // imageLabel
        Point offset;
        boolean dragging, selected;
        public ImageMover(LeftPanel lp, JPanel p, JPanel gp)
            left = lp;
            right = p;
            glassPanel = gp;
            offset = new Point();
            dragging = false;
            selected = false;
        public void mousePressed(MouseEvent e)
            Point p = e.getPoint();
            // which panel is the mouse over
            if(!setActivePanel(p));
                return;
            // get reference to imageLabel or return
            selectedComponent = getImageLabel();
            if(selectedComponent == null)
                return;
            Rectangle labelR = selectedComponent.getBounds();
            Rectangle panelR = activePanel.getBounds();
            if(labelR.contains(p.x - panelR.x, p.y))
                activePanel.remove(selectedComponent);
                selected = true;
                glassPanel.add(selectedComponent);
                offset.x = p.x - labelR.x - panelR.x;
                offset.y = p.y - labelR.y - panelR.y;
                dragging = true;
        public void mouseReleased(MouseEvent e)
            Point p = e.getPoint();
            if(!contains(glassPanel, selectedComponent))
                return;
            glassPanel.remove(selectedComponent);
            setActivePanel(p);
            activePanel.add(selectedComponent);
            Rectangle r = activePanel.getBounds();
            int x = p.x - offset.x - r.x;
            int y = p.y - offset.y;
            Dimension d = selectedComponent.getSize();
            selectedComponent.setBounds(x, y, d.width, d.height);
            glassPanel.repaint();
            activePanel.repaint();
            dragging = false;
        public void mouseDragged(MouseEvent e)
            if(dragging)
                Point p = e.getPoint();
                int x = p.x - offset.x;
                int y = p.y - offset.y;
                Dimension d = selectedComponent.getSize();
                selectedComponent.setBounds(x, y, d.width, d.height);
                if(!selected)
                    activePanel.repaint();
                    selected = false;
                glassPanel.repaint();
        private boolean contains(JPanel p, Component comp)
            Component[] c = p.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j] == comp)
                    return true;
            return false;
        private boolean setActivePanel(Point p)
            activePanel = null;
            Rectangle r = left.getBounds();
            if(r.contains(p))
                activePanel = left;
            r = right.getBounds();
            if(r.contains(p))
               activePanel = right;
            if(activePanel != null)
                return true;
            return false;
        private Component getImageLabel()
            Component[] c = activePanel.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j].getName().equals("imageLabel"))
                    return c[j];
            return null;
    }

  • How to perform a Drag and Drop operation on JButton in a JPanel?

    Hi guys,
    There is a requirement to perform Drag and Drop operation on JButton component added to a JPanel Componet.
    I could not get a proper solition to move the JButton component inside a JPanel component by drag and drop.
    I request every one to provide some related information on moving a JButton component using Mouse operation.
    Rajashekar.T

    Here is some code for moving a window around the screen. The concept would be the same for moving a button around a panel:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=599181

  • Drag and Drop image is Duplicated

    Hi,
    In my code, I want to drag and drop an image from a list populated from a folder, and its information is populated from an xml file. Now, I can drag the image from the list and drop it in the container, However, when now, I want to drag around the dropped image, it is duplicated, an extra image is created in the canvas. So, if anyone can tell me how not to create an extra copy of the image in the new container (canvas) that it was dragged to.
    Here is the code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
    name="Drag and Drop Tutorial"
    creationComplete="init()"
    initialize="pictureService.send()">
    <mx:Script>
    <![CDATA[
    import mx.controls.Image;
    import mx.core.DragSource;
        import mx.core.IUIComponent;
        import mx.managers.DragManager;
        import mx.events.DragEvent;
        import mx.controls.Alert;
        import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.collections.ArrayCollection;
    [Bindable] private var pictureData:ArrayCollection;
                private function resultHandler(event:ResultEvent):void{
                pictureData = event.result.data.image;
                private function faultHandler(event:FaultEvent):void{
                //code
    public function init():void
                // a mouseDown event will start the drag
          list.dataProvider = pictureData;
          //picture in the list is being dragged
           this.picture.addEventListener( MouseEvent.MOUSE_DOWN, beginDrag );
         // accepting a drag/drop operation...
           this.area.addEventListener( DragEvent.DRAG_ENTER, acceptDrop );
           // handling the drop...
          this.area.addEventListener( DragEvent.DRAG_DROP, handleDrop );
             public function beginDrag( mouseEvent:MouseEvent ):void
          // the drag initiator is the object being dragged (target of the mouse event)
           var dragInitiator:IUIComponent = mouseEvent.currentTarget as IUIComponent;
           // the drag source contains data about what's being dragged
           var dragSource:DragSource = new DragSource();
           // Add the data to the object.
                   dragSource.addData(1, 'value');
                    // Create a copy of the coin image to use as a drag proxy.
                    var dragProxy:Image = new Image();
                    dragProxy.source = mouseEvent.currentTarget.source;
                    dragProxy.setActualSize(mouseEvent.currentTarget.width,mouseEvent.currentTarget.height)
         // ask the DragManger to begin the drag
         DragManager.doDrag( dragInitiator, dragSource, mouseEvent, dragProxy ); 
    public function acceptDrop( dragEvent:DragEvent ):void
           var dropTarget:IUIComponent = dragEvent.currentTarget as IUIComponent;   
          // accept the drop
       DragManager.acceptDragDrop( dropTarget );
      // show feedback
            DragManager.showFeedback( DragManager.COPY );       
         public function handleDrop( dragEvent:DragEvent ):void
          var dragInitiator:IUIComponent = dragEvent.dragInitiator;
          var dropTarget:IUIComponent = dragEvent.currentTarget as IUIComponent;
            if(dragEvent.dragSource.hasFormat("items"))
              var items:Array = dragEvent.dragSource.dataForFormat("items") as Array;
            var img:Image = new Image();
            img.x=dragEvent.localX;
            img.y=dragEvent.localY;
            img.width = 50;
            img.height=50;
            img.source="assets/" + items[0].id + ".jpg";
            img.addEventListener(MouseEvent.MOUSE_MOVE,beginDrag);
            area.addChild(img);
       else
       dragEvent.dragInitiator.x=dragEvent.localX
       dragEvent.dragInitiator.y=dragEvent.localY
    ]]>
    </mx:Script>
       <mx:HTTPService id="pictureService"
    url="data/data.xml"
    result="resultHandler(event)"
    fault="faultHandler(event)"/>
    <mx:DataGrid id="list" width="238" height="200" y="26" x="10" labelField="src" dragEnabled="true"
    dataProvider="{pictureData}">
      <mx:columns>
      <mx:DataGridColumn dataField="id" id="code">
      </mx:DataGridColumn>
      <mx:DataGridColumn id="picture" draggable="true" >
      <mx:itemRenderer>
      <mx:Component>
      <mx:Image source="assets/{data.id}.jpg"  />  
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
    </mx:columns>
    </mx:DataGrid>
    <mx:Canvas id="area" x="266" y="28" width="436" height="401" backgroundColor="#c0c0c0"
    dragDrop="handleDrop(event)" >
    </mx:Canvas>
    </mx:Application>

    your handleDrop is called twice. you have assigned this eventlistener twice - one in init function and one in inline.
    remove one and it works.

  • Drag and Drop box?

    Hi all
    I want to code a Java application, that when executed, will display a box in a window. I then want to be able to drag a file from windows explorer into this box, and after dropping it in the box, I want the file name to be displayed in the console window. I'm really just interested in doing the drag and drop feature.
    Can anyone give me some links or some info that would help me do this?
    Thanks very much for any help!

    Did you try the Drag and Drop tutorial, http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html? The section titled "Importing a New Flavor: Files" may be what you're looking for.

  • How to display xy coordintes of drag and drop movie

    can someone tell me how to display the coordinates of the red
    cirle shown in the drag and drop tutorial found here:
    http://www.flashvalley.com/fv_tutorials/advanced_drag_and_drop_in_Flash/
    I have done this tutorial just fine but dont know how to
    display its x and y coordinatetes in a dynamic text box as i move
    the red circle around the screen.
    thank you for any assistance you may give.
    steve

    Hi kglad,
    I dont suppose you could show me how to create the loop? My
    own research seems to indicate the onEnterFrame method would be
    easiest.
    I am just a beginner and even this is still beyond me.
    thanks

  • Create a drag and drop target set

    Hi,
    I want to be able to create the following if possible:
    Create five words that make up a sentence and they are mixed up in order. So basically I would turn each word into a Movie clip perhaps.
    I would then like to assign a target hotspot for each word so that a user can drag the words into the correct order.
    Once they are in the correct order they click a button to go to a correct response or incorrect response. Is this possible?

    Yes, it is possible.  Try seaching Google for a tutorial using terms like "AS3 drag and drop tutorial" and/or "AS3 dropTarget tutorial"

  • Tutorial: Flex Drag and Drop

    I have just published a tutorial on Drag-and-Drop in Flex:
    http://www.flexafterdark.com/tutorials/Flex-Drag-and-Drop
    I hope it is helpful and would certainly appreciate any feedback you are willing to share.
    Thank you.
    Ben Edwards

    Ben, I have a Drag & Drop related question. Please see:
    http://forums.adobe.com/thread/534259?tstart=0
    Thanks.

  • I recently attempted to save my Notes in Macmail by dragging and dropping them into the Notes folder. On my most recent sync all Notes were deleted. Is there a way to undo this?

    I recently attempted to save my Notes in Macmail by dragging and dropping them into the Notes folder. On my most recent sync all Notes were deleted. Is there a way to undo this?

    Garret,
    is your movie in your backup folder a Quicktime movie? Then probably only have the Quicktime wrapper in your backup folder, but not the referenced media in the file fork of the movie. If you see the full quality movie in iPhoto in QuickTime player, don't drag it from the browser to the Desktop, but use "File > Reveal in Finder > Original File" to show the movie in your iPhoto Library. Select the Movie when it is revealed and ctrl-click it to open it in Quicktime Player.
    Export it from Quicktime Player with "Export to" and share it to iTunes. This way it will be converted to a .mp4 movie that embeds the missing resources.
    You can drag the converted movie from iTunes to the Desktop or share it using to Media Browser to other applications.
    Regards
    Léonie

  • Drag and drop request

    I was waiting for 1.1 as it was supposed to fix drag'n'drop issue on Windows (a lot of quiet Win-Mac differences in Lr...).
    I expected this to fix one of the main issues with Lr that I have. That is: I can send RAW files to Photoshop through CameraRAW (to be used as Smart Objects for example) from every software - 5 years old ACDSee, Photoshop Album/Elements Organizer, Win Explorer, you name it, simply by dragging them and dropping onto Ps. No luck with Lightroom! Lightroom seems to be the least integrated when it comes to this!
    But dragging files OUT OF Lr is still not working. In 1.1 there is at least a workaround but it involves copying the RAW files :-O.
    I would love the ability to drag and drop multiple files out of Lr.
    Thank You
    m.
    p.s. I would also like the sidecar files to travel with the dragged files [a bit like Easy Rider :-S]

    Witkacy > "I would love the ability to drag and drop multiple files out of Lr.
    Thank You
    m. "
    Me: "I subscribe!!"
    Put in other words, I'd like to open the selected files in LR (either RAWs or JPEGs) in third party tools. How do I do that?

  • Really stupid that you can't drag and drop photos from Finder into Events

    There is no way in iPhoto to do what I want and need to to, to wit, drag and drop photos from the Finder into existing iPhoto Events.
    It really doesn't make sense that you can't do this. First of all, calling these groups Events to begin with is not smart; in my case, a group of photos in a folder on the Finder is rarely all from one photo session or so-called "event"--- instead of Events they should just be called Groups or something, and you should be able to drop individual photos into them. I have thousands of family photos that were accumulated on my hard drives over the years, some scanned in from film negatives, slides, or prints, others from digital cameras, and when I have changed Macs and hard drives over the years, every time a folder of photos was moved from an old hard drive to a new one, or regrouped into various folders, the photos seem to have acquired new dates of origin, etc.
    Anyway, what I mean is, if Events are all time based, then somebody like me who has thousands of photos with all sorts of dates of origin, mostly unrelated to the date that the photo was actually shot, is screwed. I have old photos with new dates of origin and other mismatches between photos and the dates when they were actually shot or scanned.
    My gripe is, again, that when I find photos on my hard drives that belong in certain iPhoto Events that have already been created, I cannot just drag these photos from the Finder and drop them into the Events they belong in. Instead, the stupid program creates a new Event from each photo I try to drop into an existing Event. That means I have to chase these new photos all over the place inside of iPhoto, trying to figure out where each new photo (now called an "Event") has ended up, so that I can drag and merge it into the Event I wanted it to go into in the first place. A real pain in the neck. It simply takes too long to do this for each photo added.
    What this means is that iPhoto is not going to be a practical way to organize for a person like me until Apple makes it possible to simply drop any photo from the Finder into an existing Event. There should be an option to allow that. I'm really surprised there is not one. <edited out by Hosts>
    Tom

    Tom, iPhoto will not overwrite photos with the same name. I have plenty of photos with the same name in the same event. Each photo most likely has an internal handler that manages the photo, and not just the name of the file.
    I agree with you that this is sub-optimal, and (IMO) I think what happened is iPhoto 6 had rolls, and they came up with a really cool interface for mousing over those rolls, and decided it was more consumer friendly (and because film is a thing of the past) to call them events, rather than rolls. I think it was worth a shot, but they just slightly missed.
    Right now in iPhoto08, any serious organization is done in folders and albums. Personally, I think they need to combine the two concepts -- the great "mouse over" view of events with the organization abilities of folders and albums. I'd like an albums view where I can mouse over the albums. Actually, Aperture 2's interface for organization is more functional than iPhoto, so I am hoping some of that benefit creeps into the next iPhoto release.
    What I do is: I use events for high level grouping (like Winter 2007) and I organize folders and albums to break that down further ("trip to Montreal" "Christmas" etc.). But I do it backwards. I fill albums first, then I organize events.
    When I drag in pictures to iPhoto, first I make the target album in iPhoto that I want to populate, then I drag the photo directly to that album (not to events). iPhoto automatically puts the photo into the album I created and also into a new event. Later, I go into events, right-click on this new event to "open event in separate window" then I move around the events view, to drop in the pictures from the "import" event I just created. If I move all the pictures into other events, iPhoto automatically deletes the event I just emptied. You could skip the event organization all together if you wanted to, but you'd lose the cool mouse-over feature, which can be handy.
    One nice thing about having events AND albums is you can have the photo just once in iPhoto, in an event, but then have the photo appear in as many albums as you want (as well as projects and web galleries) all while only having one photo on your hard drive. So, there are benefits to events, but I think iPhoto is missing just a couple little bits of organizational ability to make it perfect. (and yes, I've submitted this all to Apple as feature requests)
    Just in case you don't know -- events don't have any hierarchy. That is, you can't nest events. But you can have folders with subfolders, and any folder can contain albums. Albums cannot have sub-albums, and folders don't hold photos. Only albums hold photos, and folders (or sub-folders) hold albums. Try create some folders and albums and you'll get the hang of it. One other issue that Apple needs to address. When you create a new folder or album, it doesn't put it right where you want it, but rather puts it at the bottom of the list, so you have to drag it up to where you want it. Try it out, and you'll see what I mean, then submit it as a feature request to improve that.
    I agree it's not perfect, but it's not too bad once you get used to it. And the benefits of working with the rest of the features of iPhoto is worth it. I'm just really hoping they do a few tweaks on the next release. They are near greatness here. They could just use a little nudge on the last bits. (in my opinion of course. Others may disagree, but I've talked to enough people who have the same issues you are having to know we are not alone on this).

  • Open a File in a JTextPane via Drag and Drop

    Hi,
         I have a simple JTextPane in a Swing App on Windows XP. I would like to know if it is possible for me to be able to add the functionality such that I can drag a text file to the JTextPane and it would open the file inside the Pane. Is this possible? If yes then how do I implement it? (I am not insisting on the app working on non-Win XP systems � so portability is not a concern.)
         I have tried to search for the drag and drop stuff but I am confused. First, which interfaces should I implement i.e. DragGestureListener, DragSourceListener, DropTargetListener or what?
         I would be grateful for any pointers.
    Thanks a lot,
    O.O.

    1. http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html - This link did have the information but has since been updated and no longer points to the relevant information that I have since used.
    So you where given a link with the appropriate informaton, but Sun has changed the information and you are blaming us for not helping? Unbelievable!
    Here is a link to the old tutorial:
    https://www.cs.auckland.ac.nz/references/java/java1.5/tutorial/uiswing/dnd/intro.html#importFiles
    Now tell us how that does not do exactly what you wanted?
    I really don�t know why some people waste their time here just providing you with linksBecause most people like yourself don't know how to ask a question. DnD is a complex topic. The only way to learn it is to read a tutorial and experiment. What a better way to learn than to play with a working example. You are given many working examples in the tutorial.
    You did not state wihich example you had changed. You did not state what problems you where having.
    The best you could state was "I'm confused". You where asked to clarify your problem/confusion but didn't. We are not mind readers so we couldn't provide further help.
    I agree I am wasting my time helping someone who doesn't even appreciate the effort made by the many individuals of the forum and I won't make that mistake again.

  • Drag and Drop between two JTables

    I tried to implement drag and drop between two JTables using data transfer, but i did not get it to work, that dnd works in both directions. i have my own transferhandler, but if is use setTransferHandler(handler), i'm no longer able to start a drag from that table. i also tried to use a mouse listener to call exportAsDrag, but i only works in one direction. any ideas or examples?

    That is a rather large request, and indicates that you have likely not spent much time researching the subject before posting. Read up on Swing drag & drop here (http://java.sun.com/docs/books/tutorial/dnd/), then ask specific questions about something you don't understand, problems with your implementation, etc.
    Mike

  • Drag and Drop items among JList

    Hi,
    I want to drag item from one JList and drop into another JList using JFrame in java Swing. Please provide me code for this.
    Thanks
    Nitin

    You need to implement a drag-and-drop (dnd) behaviour between your swing components.
    Like most programming tasks it looks harder than it really is. Basically you need a DragSource and a DropTarget with a Transferable object in between. This Transferable object is the object from your list.
    Here is Sun's tutorial on it... http://java.sun.com/docs/books/tutorial/dnd/
    Good luck.

Maybe you are looking for

  • Monitor for HDV footage?

    I am using FCE4HD and ask if there is any monitor through which I can play the edited footage as on my G4 and, if so, how I should connect the two. I believe FCE4 uses an Apple Intermediate Codec which won't allow this but...........is there a way, a

  • Calling EJB from Java Stored Procedures

    Hi, I am trying to call an Enterprise Java Bean from stored procedure. This stored procedure calls a java program. As long as it is a simple java program it works fine and loadjava.exe does not give any problem (neither compile-time nor run-time). It

  • How to delete and create the CCM MASTER CATALOG in Catalog Content?

    Hi All, Please provide the solution as we are in real trouble. We have to delete master catalog and upload it again. Deletion is done because the mapping and all are being corrupted. SAP has suggested to delete the catalog and again upload it and do

  • PC2700 ram

    I am looking to get new ram for my 800 mhz ibook G4. The apple web site says that I should get PC2100 ram, but also says that it is PC2700 compatible. If I buy the PC2700 will it be any different than the PC2100. Does it really matter?

  • Policies for OS X

    Obviously there's no forum for Mac Policies, does anyone know if that's a feature coming to ZCM 11.X? I was specifically looking for iPrint policies. Got caught waiting for the iPrint patch for 10.8, so I was hoping to deliver the printers later on.