Drag and drop icons

hello world....
in the process of learning i'm trying to create a small java app that resizes and processes graphics, (using imagemagick api).
what i'd like to be able to do is drag the icon (or shortcut) to my java app and then have the app process that, just as a windows app would do. in fact all i need really is the location of the file the user has dragged and dropped onto my app, although it would be nice if i could indicate somewhere that the file was being processed!
i understand the use of the drag and drop re the text within java, but how do i go about dragging an external icon over a java app and having that pass me the file location (which is actually all i need...)
thanks in advance!

i understand the use of the drag and drop re the text
within java, Are you sure?
Read this:
http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html

Similar Messages

  • Drag and drop icons from onside of the split pane to the other side.

    Hello All,
    I am tring to write a program where i can drag and drop icons from the left side of the split pane to the right side. I have to draw a network on the right side of the split pane from the icons provided on the left side. Putting the icons on the labels donot work as i would like to drag multiple icons from the left side and drop them on the right side. CAn anyone please help me with this.
    Thanks in advance
    smitha

    The other option besides the drag_n_drop support
    http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.htmlis to make up something on your own. You could use a glasspane (see JRootPane api for overview) as mentioned in the tutorial.
    Here's another variation using an OverlayLayout. One advantage of this approach is that you can localize the overlay component and avoid some work.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    public class DragRx extends JComponent {
        JPanel rightComponent;
        BufferedImage image;
        Point loc = new Point();
        protected void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            if(image != null)
                g2.drawImage(image, loc.x, loc.y, this);
        public void setImage(BufferedImage image) {
            this.image = image;
            repaint();
        public void moveImage(int x, int y) {
            loc.setLocation(x, y);
            repaint();
        public void dropImage(Point p) {
            int w = image.getWidth();
            int h = image.getHeight();
            p = SwingUtilities.convertPoint(this, p, rightComponent);
            JLabel label = new JLabel(new ImageIcon(image));
            rightComponent.add(label);
            label.setBounds(p.x, p.y, w, h);
            setImage(null);
        private JPanel getContent(BufferedImage[] images) {
            JSplitPane splitPane = new JSplitPane();
            splitPane.setLeftComponent(getLeftComponent(images));
            splitPane.setRightComponent(getRightComponent());
            splitPane.setResizeWeight(0.5);
            splitPane.setDividerLocation(225);
            JPanel panel = new JPanel();
            OverlayLayout overlay = new OverlayLayout(panel);
            panel.setLayout(overlay);
            panel.add(this);
            panel.add(splitPane);
            return panel;
        private JPanel getLeftComponent(BufferedImage[] images) {
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            for(int j = 0; j < images.length; j++) {
                gbc.gridwidth = (j%2 == 0) ? GridBagConstraints.RELATIVE
                                           : GridBagConstraints.REMAINDER;
                panel.add(new JLabel(new ImageIcon(images[j])), gbc);
            CopyDragHandler handler = new CopyDragHandler(panel, this);
            panel.addMouseListener(handler);
            panel.addMouseMotionListener(handler);
            return panel;
        private JPanel getRightComponent() {
            rightComponent = new JPanel(null);
            MouseInputAdapter mia = new MouseInputAdapter() {
                Component selectedComponent;
                Point offset = new Point();
                boolean dragging = false;
                public void mousePressed(MouseEvent e) {
                    Point p = e.getPoint();
                    for(Component c : rightComponent.getComponents()) {
                        Rectangle r = c.getBounds();
                        if(r.contains(p)) {
                            selectedComponent = c;
                            offset.x = p.x - r.x;
                            offset.y = p.y - r.y;
                            dragging = true;
                            break;
                public void mouseReleased(MouseEvent e) {
                    dragging = false;
                public void mouseDragged(MouseEvent e) {
                    if(dragging) {
                        int x = e.getX() - offset.x;
                        int y = e.getY() - offset.y;
                        selectedComponent.setLocation(x,y);
            rightComponent.addMouseListener(mia);
            rightComponent.addMouseMotionListener(mia);
            return rightComponent;
        public static void main(String[] args) throws IOException {
            String[] ids = { "-c---", "--g--", "---h-", "----t" };
            BufferedImage[] images = new BufferedImage[ids.length];
            for(int j = 0; j < images.length; j++) {
                String path = "images/geek/geek" + ids[j] + ".gif";
                images[j] = ImageIO.read(new File(path));
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(new DragRx().getContent(images));
            f.setSize(500,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class CopyDragHandler extends MouseInputAdapter {
        JComponent source;
        DragRx target;
        JLabel selectedLabel;
        Point start;
        Point offset = new Point();
        boolean dragging = false;
        final int MIN_DIST = 5;
        public CopyDragHandler(JComponent c, DragRx dr) {
            source = c;
            target = dr;
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            Component[] c = source.getComponents();
            for(int j = 0; j < c.length; j++) {
                Rectangle r = c[j].getBounds();
                if(r.contains(p) && c[j] instanceof JLabel) {
                    offset.x = p.x - r.x;
                    offset.y = p.y - r.y;
                    start = p;
                    selectedLabel = (JLabel)c[j];
                    break;
        public void mouseReleased(MouseEvent e) {
            if(dragging && selectedLabel != null) {
                int x = e.getX() - offset.x;
                int y = e.getY() - offset.y;
                target.dropImage(new Point(x,y));
            selectedLabel = null;
            dragging = false;
        public void mouseDragged(MouseEvent e) {
            Point p = e.getPoint();
            if(!dragging && selectedLabel != null
                         && p.distance(start) > MIN_DIST) {
                dragging = true;
                copyAndSend();
            if(dragging) {
                int x = p.x - offset.x;
                int y = p.y - offset.y;
                target.moveImage(x, y);
        private void copyAndSend() {
            ImageIcon icon = (ImageIcon)selectedLabel.getIcon();
            BufferedImage image = copy((BufferedImage)icon.getImage());
            target.setImage(image);
        private BufferedImage copy(BufferedImage src) {
            int w = src.getWidth();
            int h = src.getHeight();
            BufferedImage dst =
                source.getGraphicsConfiguration().createCompatibleImage(w,h);
            Graphics2D g2 = dst.createGraphics();
            g2.drawImage(src,0,0,source);
            g2.dispose();
            return dst;
    }geek images from
    http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html

  • Desktop drag and drop icon for my "other" computer

    i really need an icon for my MacBookPro desktop to reside on my Mac Pro desktop (and vice versa) so that I can just drag and drop copy (or move) data from one volume to another. sort of like what I have with my dropbox icon in the sense that I can just keep this on my desktop and in the View Pane of Finder and drag and drop items or open the volume etc.
    is this possible and i am just not getting it to work because i don't have things set to mount automatically or is there a restriction that does not allow this that I don't understand?
    i am on snow leopard and the connection is via wi, but I could plug in via ethernet when i know i will need to do this sort of moving of data a lot.
    thanks for clearing any of this up for me.
    - jon

    if as3, create a sprite or movieclip and use:
    image1.addEventListener(MouseEvent.MOUSE_DOWN,downF);
    image1.addEventListener(MouseEvent.MOUSE_UP,upF);
    function downF(e:MouseEvent):void{
    Sprite(e.currentTarget).startDrag();
    function upF(e:MouseEvent):void{
    Sprite(e.currentTarget).stopDrag();

  • Drag and drop icons between regions

    I have two regions in a page. Each of the regions show employers available in different departments and each employer is represented with icons. is it possible to drag and drop employees between these two regions (departments) and finally save the latest changes made to the employes/deparments into the table?. any ideas are appreciated.
    thanks,
    Surya

    Yes it is possible, but not so easy. If you'll be at OOW this year, you can come to my session (S301752, Monday 13:00-14:00) - I will show something similar there. If you're not so lucky, you can read the excellent blogpost of my colleague at [http://rutgerderuiter.blogspot.com/2008/07/drag-planboard.html]
    Cheers
    Roel

  • I am unable drag and drop icons on to customized toolbar... they simply will not drag How do I resolve this? Do I need to download something?

    I click to customize toolbar and add a new one. Then I try to drag an icon from the panel onto the new toolbar. Nothing. I am unable to do so. None of the icons are grabbable, despite the fact that the fat hand appears when I hover over them, indicating that they are ready for drag and drop (or at least that is what I am programmed to think)

    See:
    * http://kb.mozillazine.org/Corrupt_localstore.rdf
    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]

  • Cannot drag and drop icons,

    I'm working on a Mac Power PC G4, OS X, version 10.2.8. About a week ago I started noticing a problem dragging and dropping items with the trackpad. I can click on a file to open it, but I cannot drag and drop files to move them. If I am in a Word document, I can no longer drag highlighted text around either, or drag songs to playlists in iTunes. However, if I open a window, I can drag the open window around, just not any of the files displayed in it. The same thing happens when I hook up a mouse. I've checked the Finder view options and have done a test to check that it is not a corrupted system preferences and have tried many of the things listed on discussions I have seen online. I'm hoping that I don't have to resort to reinstalling the operating system. Everything was working fine until about a week ago, and I am aware of no changes or damage to the computer that could have caused this problem. Any help?

    I created a new account with administrative privelages, but the new account still does the same thing. I also tried trashing com.apple.systemuiserver.plist as suggested to me by someone else, and it had no effect.
    Thanks for you idea.

  • Can no longer drag and drop icons

    Hello All
    All of a sudden no users on my mac can "drag and drop" on desktop in finder or in the dock. can move open windows. have tried my old mouse and just the same
    also firefox stopped working at the same time wont load!
    Help please

    Hi again,
    I am sorry that didn't work. The only other thing i can think of is, have you checked the setting in each user account? In system preferences, users or user accounts (sorry i am on a PC at the moment so can't remember what it is called)
    I know there is a setting in there to stop users making changes to the dock, maybe this has changed and that is causing these problems?

  • How to drag and drop icon in the browser

    hi
    i Have A web page that i should drag some responces from right to their correct location in Left.in pc I hold left mouse buttom and drag icon into its Correct place and drop it but I can't do that on the android browser. how should I do that? and firefox is only
    browser that support my web page.

    Some websites are programed to recognize tap actions instead of clicks, but others design the site to have a mobile version and a desktop version.
    However I do not know if this will do this automatically. For example if you have a drop down menu in a form, it will drop down if you tap it on a mobile device and will do the same thing if you click it in a desktop browser.
    It is possible to try to long tap then try to drag it, but if the website does not have it programmed, it may not work. There is Javascript UI touch punch that you can check out to develop this capability, but that would be a question for stackoverflow.com.
    I am sorry I could not be more helpful.

  • Will we ever get to drag and drop icons into our schedules, ever?

    I was wondering if iCal would ever have icons like most calenders, ones we can copy and paste from out clipboards to use for meeting schedules, dates, anything we like.
    will it ever happen YET?

    they been around since the 80's, anyone want these feature?
    atleast to see the contacts fotos in the calender to have a hint in a months view, as a pop up, something?

  • I can't drag and drop icons

    Whenever I click on something and try and drag it somewhere else it just doesn't work at all.

    Restart and see if that solves your issue.

  • I cannot drag and drop

    I was trying to clean up my computer yesterday by deleting some files, mainly clearing the cache and deleting large files that i knew what they were.  I turned off my computer for the night, and now today when i turned on my computer I can no longer drag and drop icons or cut and paste files from folder to folder. 

    Also, after the video thumbnail is ghosted, if I click on the ghosted thumbnail the thumbnail image does not appear in the preview window. Instead, the preview window turns black.
    Also, if I double click the ghosted thumbnail I do not get the Clip info dialog. It's as if the clip no longer exists, but I can see it's ghosted thumbnail.
    Also, I showed my wife the problem and she just told me she was using iMovie 2 days ago with no problem.
    Ralph Ocampo

  • Can not drag and drop or copy and paste

    It is as simmple as the title. I can not drag and drop icons or text or folders. Nothing. As for cut, copy, and paste they do not work either. I am trying to back up my files so I can do a clean install of snow leopard. I have leopard currently.

    So Copy/Paste, etc. isn't working in say Text Edit?
    On the Drag & Drop, where are you trying to drop them, & does the icon move but just not copy?

  • Drag and drop help (urgent)

    I need to write a program where I can drag and drop icons between and within a split pane. Any suggestion of what package I should look into? thanks

    Java provides two separate packages for drag and drop. java.awt.dnd and java.awt.datatransfer. These packages contain interfaces and classes for drag and drop. So pls go thru these classes.

  • I can't drag and drop anylonger!!!

    Apple family! I can't drag and drop icons anylonger... therefore, I can't copy stuff from one folder to another!!! REALLY BAD! What can I do? Thanks.

    From:
    https://discussions.apple.com/message/18436580#18436580
    Press Command(cmd) + Alt+ Esc, select Finder and press "relaunch". That fixed it for me

  • Drag and drop several files

    Hi,
    I'm using iPhoto '11 (version 9.4.2) and when I try to drag and drop several files into a folder, it fails.
    Actually it just does nothing: the drag and drop icon is created with the accurate numbre of items in a red star, the folder blinks but when I release the mouse, nothing happens.
    It fails sometimes with 3 photos, sometimes with 30.
    What's more puzzling is that it sometimes works: if I drag and drop of a single photo it always works. And I'm sometimes able to drop 10 or more photos.
    I'm running on a macbook pro retina with lion (10.8.2).
    Any idea of logs I could look at for some informations, some errors messages?
    Thanks,
    Laurent.

    I guess it creates new photos, hence it modifies the timestamps whereas drag and drop does not.
    There are two kinds of metadata involved when you consider  jpeg or other image file.
    One is the file data. This is what the Finder shows. This tells you nothing about the contents of the file, just the File itself.
    The problem with File metadata is that it can easily change as the file is moved from place to place or exported, e-mailed, uploaded etc.
    Photographs have also got both Exif and IPTC metadata. The date and time that your camera snapped the Photograph is recorded in the Exif metadata. Regardless if what the file date says, this is the actual time recorded by the camera.
    Photo applications like iPhoto, Aperture, Lightroom, Picasa, Photoshop etc get their date and time from the Exif metadata.
    When you export from iPhoto to the Finder new file is created containing your Photo (and its Exif). The File date is - quite accurately - reported as the date of Export. However, the Photo Date doesn't change.
    The problem is that the Finder doesn't work with Exif.
    So, your photo has the correct date, and so does the file, but they are different things. To sort on the Photo date you'll need to use a photo app.

Maybe you are looking for

  • How do I transfer bookmarks from a pc to a macbook?

    I just purchased a macbook air. I installed Firefox on the Air and would like to transfer my Bookmarks from my Dell pc to the Air.

  • What is this Figure and... it's correct?

    2 questions: 1) What is this figure (see under)? I want know what is the box (target_type) in which there is icon that I know. What is its function? How can I find it? 2)  It's correct this for expert and excellent Labview programmer (see the Figure)

  • Canon 5D lll raw to Aperture - under exposed

    Converting Canon 5D lll raw files via Aperture is producing a very under exposed image. The same file converted via Canon DPP or Photoshop CS5 appear 'correct.' Why is this so different? I have to increase the exposure in Aperture to 1.25 (default is

  • Error: ORA-12560

    Hi Everybody I keep getring the above Error, when I want to Connect when I am in Form Developer Platform. I was told that, I should set the Oracle Home to the Oracle developer Suite Home. Could you please tell me How can I do this? I am new to Oracle

  • MBP won't remember to connect to TC

    Hello all, I just set up my TimeCapsule 1TB over the past weekend. It seems to be working fine except for the following: It is at my home. Whenever I have come home from work and started my MBP, it will not connect to my home network. TC is acting as