Drag and Drop Export Done is called too soon...

Hi,
I am trying to drag and drop a JLabel from a JPanel into another JPanel. I am no where near to figuring it out, but just for starters I notice that the exportDone() method is called in my custom TransferHandler immediately when the drag begins. Even stranger, createTransferable() is never called. (I am comparing my code to the DragPictureDemo that I found online). The question is, why is exportDone called immediately? Code below. Thanks. (BTW, any other suggestions about what I'm trying to do would be appreciated. I'm not confident in the direction I'm taking here... have yet to understand the Swing DnD mechanism...)
From DragPictureDemo, I notice that createTransferable and exportAsDrag are called immediately upon drag, and exportDone is called at the drop.
Here is my code: First, the main class Testola.java:
* Created on Oct 31, 2007
* Copyright 2006 Michael Anthony Schwager.
* This software comes without warranty or applicability for any purpose.
* Rights granted for any use.
package testola;
import javax.swing.*;
import java.awt.*;
public class Testola implements Runnable {
      * @param args
     public void run() {
          /*char[] stdout_arr={};
          String blah;
          blah=new String(stdout_arr, 0, 0);
          StringBuffer buf=null;
          System.out.println("Hello world." + " wow" + null + "<-null");*/
          // --------- FRAME ---------
          JFrame frame=new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setBounds(30,30,500,400);
        JDesktopPane dtp=new JDesktopPane();
        frame.getContentPane().add(dtp);
        // First Internal Frame; false means no close box.
        JInternalFrame jif=new JInternalFrame("One", true, false, true, true     ); //jif.setBounds(0,0,100,50);
        DnDJPanel contentPanel=new DnDJPanel(); contentPanel.setBackground(new Color(255,255,180));
        contentPanel.setLayout(null);
        // Then JLabels, first 1
        JLabel test1=new JLabel("test1!"); test1.setBounds(0, 0, 50, 20);
        test1.setBorder(BorderFactory.createLineBorder(Color.RED));
        //test1.setTransferHandler(new JComponentTransferHandler());
        contentPanel.add(test1);
        // 2
        JLabel test2=new JLabel("test2!"); test2.setBounds(10, 30, 50, 20);
        test2.setBorder(BorderFactory.createLineBorder(Color.GREEN));
        //test1.setTransferHandler(new JComponentTransferHandler());
        contentPanel.add(test2);
        // Finalize Frame
        contentPanel.setBounds(0,0,250,140);
        contentPanel.setTransferHandler(new JComponentTransferHandler());
        contentPanel.setVisible(true);
        jif.setBounds(10,10,250,140);
        jif.setContentPane(contentPanel);
        jif.setVisible(true);
        // Second Internal Frame
        DnDJInternalFrame jif2=new DnDJInternalFrame("Two", true, false, true, true     );
        // JPanel and jtextfield to add to Frame2
        // Finalize Frame2
        jif2.getContentPane().setLayout(null);
        jif2.setBounds(120,150,200,155);
        jif2.setVisible(true);
        dtp.add(jif);
        dtp.add(jif2);
        try {jif.setIcon(false);} catch (Exception e) {System.err.println("setIcon exception");}
          frame.setVisible(true);
     public static void main(String[] args) {
          Testola testola=new Testola();
          try {EventQueue.invokeAndWait(testola);} catch (Exception e) { System.out.println(e);};
          //testola.run();
          System.out.println("Exit");
}Now, my JComponentTransferHandler.java:
* Created on Apr 12, 2008
* Copyright 2006 Michael Anthony Schwager.
* This file is part of testola.
* testola is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* testola is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*  (You should have received a copy of the GNU General Public License
*  along with testola; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
package testola;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.event.InputEvent;
import javax.swing.JComponent;
import javax.swing.TransferHandler;
public class JComponentTransferHandler extends TransferHandler {
     public JComponentTransferHandler() {
          super();
     public JComponentTransferHandler(String property) {
          super(property);
     public void exportDone(JComponent source, Transferable data, int action) {
          super.exportDone(source, data, action);
          System.out.println("Export is done!");
     public boolean importData(JComponent comp, Transferable t) {
          boolean res;
          res=super.importData(comp, t);
          System.out.println("Import is done! " + res);
          return res;
     public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
          boolean res;
          res=super.canImport(comp, transferFlavors);
          System.out.println("Can import: " + res);
          return res;
    public void exportAsDrag(JComponent comp, InputEvent e, int action) {
         super.exportAsDrag(comp, e, action);
         System.out.println("Export as drag: " + comp.getClass().getName());
    protected Transferable createTransferable(JComponent c) {
        System.out.println("createTransferable, arg: " + c.getClass().getName());
         Transferable t=super.createTransferable(c);
        return t;
}Edited by: Hushpuppy on Apr 13, 2008 7:59 PM
Edited by: Hushpuppy on Apr 13, 2008 8:02 PM
Edited by: Hushpuppy on Apr 13, 2008 8:13 PM

No idea whether this will be helpful, but exportDone() is not called immediately if you remove the call to super.exportAsDrag.
db
edit Since your earlier post, I've been trying to teach myself Swing DnD, but am finding the documentation confusing and the tutorials primitive... I'd reached a conclusion, which has every chance of being wrong, that I should call createTransferable from exportAsDrag. FWIW these are the methods as of now -- nothing works :-(   @Override
   public void exportAsDrag(JComponent comp, InputEvent e, int action) {
      // count is a instance field to monitor repeated calls
      System.out.println(count + ". " + "exportAsDrag"); count++;
      //super.exportAsDrag(comp, e, action);
      // dragSource is a instance field of type Container
      dragSource = comp.getParent();
      createTransferable(comp);
   @Override
   protected Transferable createTransferable(JComponent child) {
      System.out.println(count + ". " + "createTransferable"); count++;
      // ComponentHandler implements Transferable
      Transferable t = new ComponentHandler(child);
      return t;
   }The commented line is from testing a possible cause of your problem, since my code never gets as far as exportDone() :-(
Edited by: Darryl.Burke

Similar Messages

  • I want to do a drag and drop but don't want it to be a test

    Hi,
    Any help would be greatly appreciated.
    I am using Captivate 7.
    I want to do a drag and drop but don't want it to be a test. This is for brain storming---not a test.
    None of the items to drag are correct or incorrect---they are just ideas. For example the 20 items could be different things you might put in your suitcase for vacation. There are no wrong answers---just your preference.
    There are 20 items to be dragged. There is only one drag target. All 20 items can go to that 1 drag target.
    I don't want the learner to have to drag all of the items to the target in order to finish. For example, the learner might leave 3 items out because the learner doesn't like those items. I want the learner to be able to hit submit (or any other button) at any time and go to the next slide immediately, not have to finish the drag and drop. Any ideas? 
    thanks!

    Also be aware that if you add a quiz to the project, that the drag and drop and quiz affect each other.
    In a way we have been cheated into thinking that is also a learning tool for repeated attempts. With a quiz in the project it does not work.
    I also tried it without the quiz. When learners now use it, the drag and drop will "hang" at times. EMBARRASING when a client phones you with a stuck learning session!!
    I have spent hours with the online Adobe dudes. It some or other "buG".
    "BUG" is IT code for "we designed something but did not test it well enough and now we pretend that it is some mysterious organic organism that is maliciously undermining our design"  

  • Drag And Drop operations do not call custom IRM Protector

    We are developing our own custom IRM Protector, 
    So far we have successfuly integrated our IRM Protector into Sharepoint, and download operations and upload operations do protect and unprotect documents. Also move operations between libraries, through Send To ribbon action, call HrProtect and HrUnprotect
    methods as needed. 
    However, in our test environments, when using drag and drop operations between Libraries or folders, the IRM Protector is not being called at all. We have tried to update our test environments to the latest Cumulative Update, without success. Is there any
    known bug around the drag and drop functionality? 
    If true, Drag and Drop suposes a great security threat, and we cannot deliver our protection product to our customers, as it would mean document protections could be bypassed by a simple sharepoint operation.
    Thanks,

    We are developing our own custom IRM Protector, 
    So far we have successfuly integrated our IRM Protector into Sharepoint, and download operations and upload operations do protect and unprotect documents. Also move operations between libraries, through Send To ribbon action, call HrProtect and HrUnprotect
    methods as needed. 
    However, in our test environments, when using drag and drop operations between Libraries or folders, the IRM Protector is not being called at all. We have tried to update our test environments to the latest Cumulative Update, without success. Is there any
    known bug around the drag and drop functionality? 
    If true, Drag and Drop suposes a great security threat, and we cannot deliver our protection product to our customers, as it would mean document protections could be bypassed by a simple sharepoint operation.
    Thanks,

  • Drag and Drop export of vcards to Mail no longer works in Snow Leopard

    In 10.5, you could drag a vcard from the Address Book application, drop it on the Mail icon on the dock, and the vcard would be automatically attached to a new mail message. This no longer works in 10.6. Tested on a G4 iMac running Leopard and a Mac Pro on Snow Leopard. Kind of a bummer, as I used to send new contacts to business partners all the time this way.

    There have been other reports of drag and drop to the icon not working like it did/should.
    I imagine rewriting it for Docksposé caused a lot of code changes. Hopefully, they will fix the things that have fallen through the cracks.
    I forgot to mention the only workaround I can find is to create the new message first, and then use Docksposé to drop the vCards onto the new message.
    Message was edited by: Barney-15E

  • Is it possible to add a drag and drop interaction to a called image in a contaner?

    this forum is my last hope =( i know how to do drag and drop
    by itself, however right now i have my flash set up so that when
    you click BUTTON A, it does:
    on (release) {
    _root.gotoAndPlay ("photo1");
    once it goes to "photo1", on that frame, i wrote actions on
    the frame to:
    var myMCL:MovieClipLoader = new MovieClipLoader ();
    myMCL.loadClip ("images/heritageBrochureFront.png",
    "container_mc");
    stop();
    so it loads my picture into the container. my question, once
    the image it in the container, can i add drag and drop interaction
    to it? i would really love an easy solution.

    yes. there are a couple of ways to do this.
    one is the create a child movieclip of container_mc and load
    into that child and assign your onPress/startDrag
    onRelease/stopDrag methods to container_mc.
    a second way is to load into container_mc (like you're
    currently doing), wait until loading is complete (ie, use the
    onLoad method of an mcl listener) and then assign your methods to
    container_mc.

  • [SOLVED] Thunar 1.6 doesn't drag-and-drop with the right mouse button

    Hallo all.
    It might be something I've done (though I did delete my ~/.config/Thunar directory before upgrading), but Thunar doesn't let me drag-and-drop with the right mouse button, thus stopping me from copying something instead of moving it, etc. Has anyone else had that too?
    Last edited by GordonGR (2012-12-28 14:34:20)

    Joel wrote:
    anonymous_user wrote:Is it supposed to be with the right-mouse button? I always thought drag and drop was done with the left button?
    Could be right-hand user
    Come on! Read what GordonGR wrote!
    Microsoft Windows, Nautilus, the Haiku Tracker, and probably many other file managers have a feature where, when you right-click or middle-click and drag an icon to a new location, a pop-up menu appears and asks what you'd like to do (Move, Copy, Link). I thought I used to use this feature in Thunar too but it seems to have stopped working in recent versions. Has anyone else had any experience with it?
    EDIT: Here's random blogger talking about the feature in an older version of Thunar: http://jeromeg.blog.free.fr/index.php?p … and-tricks So that's good, I wasn't just imagining the feature.
    Last edited by drcouzelis (2012-12-12 03:45:05)

  • When I try to move one layer to another layer, my drag and drop won't do it. What do I need to do?

    The drag and drop technique,don't seem to work in my program. is there something I need to configure?

    For an example we will use tab 1 for the old image and tab 2 for the new image. In that the images from tab 1 will be dragged and dropped to tab 2.
    Open two images as per above.
    Click tab 1 to make that the active document if it is not already
    In the layers panel click on the layer that has the image
    In the document window (the canvas) move the cursor over the image, press left mouse button down and drag to tab 2 (don't let go of mouse button)
    The document in tab 2 will become active
    With the mouse button still held down drag the cursor over the center of the document (canvas) {If you wish to center the image on the canvas you may now hold down the shift key while the mouse button is still held down
    Let go of mouse button then let go of shift key
    You should now see two layers in your layers panel. One image is on top of the other so you can not see the bottom image
    You now have a few choices, you can expand the canvas and move the image(s) so they are side by side
    You can add a mask to the top layer and paint away what you don't want
    You can select parts of the background of the top image then delete it
    You can lower the opacity to blend the two images into one
    You can use a blend mode to blend the two images into one
    This apart is totally up to you and if you need any further advice let us know or if you are still stuck, please capture your screen so we can see what you did and have the layers panel open with any collapsed layers expanded.

  • Drag and drop in jscrollpane

    Hi all
    I have 2 different scrollpanes setup in 2 different panels. one of them contains a rdf graph structure which is generated by me using several other APIs. Now I want to drag and drop some of the nodes from one scroll pane to another. The nodes have features to be selected. I am totally new to java drag n drop. Can some one help me by providing some basic code to move stuff between scrollpanes??

    No, I do not (and cannot) use TransferHandler and such. The Drag and Drop is done manually by using MouseListener and MouseMotionListener.
    And also, my problem is not the drag and drop functionality. The problem is only the scrolling.

  • How do I set up my drag and drop questionaire to export to a XML file?

    How do I set up my drag and drop questionaire to export to a
    XML file?
    I have a 70 seperate SWF files that pose a question and
    contain a drag and drop rank order response of 1,2,3,4.How do I set
    up a XML file that receives the responses.I don't understand how to
    do the Actionscript
    and get my responses to connect to the XML.Please
    Help!Thanks!
    Here's an example of my XML.
    <assessment>
    <sessionid>ffae926ea290ee93c3f26669c6c04a92</sessionid>
    <request>save_progress</request>
    <question>
    <number>1</number>
    <slot_a>2</slot_a>
    <slot_b>1</slot_b>
    <slot_c>4</slot_c>
    <slot_d>3</slot_d>
    </question>
    <question>
    <number>2</number>
    <slot_a>4</slot_a>
    <slot_b>3</slot_b>
    <slot_c>2</slot_c>
    <slot_d>1</slot_d>
    </question>
    <question>
    <number>3</number>
    <slot_a>1</slot_a>
    <slot_b>2</slot_b>
    <slot_c>3</slot_c>
    <slot_d>4</slot_d>
    </question>
    </assessment>

    Use XML.sendAndLoad.
    http://livedocs.macromedia.com/flash/8/main/00002879.html
    You will need a server script to receive the XML structure
    and it depends on
    the server scripting language how you obtain that data. Then
    you can either
    populate a database or write to a static file or even email
    the XML data
    received from Flash.
    For a basic example, I have two links I use for students in
    my Flash
    courses:
    http://www.hosfordusa.com/ClickSystems/courses/flash/examples/XMLASP/Ex01/XMLASPEchoEx01_D oc.php
    http://www.hosfordusa.com/ClickSystems/courses/flash/examples/XMLPHP/EX01/XMLPHPEchoEx01_D oc.php
    Lon Hosford
    www.lonhosford.com
    May many happy bits flow your way!
    "kenpoian" <[email protected]> wrote in
    message
    news:e5i9hp$cs6$[email protected]..
    How do I set up my drag and drop questionaire to export to a
    XML file?
    I have a 70 seperate SWF files that pose a question and
    contain a drag and
    drop rank order response of 1,2,3,4.How do I set up a XML
    file that receives
    the responses.I don't understand how to do the Actionscript
    and get my responses to connect to the XML.Please
    Help!Thanks!
    Here's an example of my XML.
    <assessment>
    <sessionid>ffae926ea290ee93c3f26669c6c04a92</sessionid>
    <request>save_progress</request>
    <question>
    <number>1</number>
    <slot_a>2</slot_a>
    <slot_b>1</slot_b>
    <slot_c>4</slot_c>
    <slot_d>3</slot_d>
    </question>
    <question>
    <number>2</number>
    <slot_a>4</slot_a>
    <slot_b>3</slot_b>
    <slot_c>2</slot_c>
    <slot_d>1</slot_d>
    </question>
    <question>
    <number>3</number>
    <slot_a>1</slot_a>
    <slot_b>2</slot_b>
    <slot_c>3</slot_c>
    <slot_d>4</slot_d>
    </question>
    </assessment>

  • Can i make a book in iPhoto without using any of the built in layout templates, which are too limiting when i have already cropped my pictures to show just what I want. Ideally I just want to drag and drop and arrange and size the pictures myself

    Can i make a book in iPhoto without using any of the built in layout templates, which are too limiting when i have already cropped my pictures to show just what I want. Ideally I just want to drag and drop and arrange and size the pictures myself

    If you have Pages you can create customs pages for your book as TD suggested. If you have Pages from iWork 09 or 11 this app will add 80 or so additional frames to those offered:  Frames and Strokes Installer. Don't use it on the latest Pages version, however.
    This tutorial shows how to create a custom page with the theme's background: iP11 - Creating a Custom Page, with the Theme's Background for an iPhoto Book.  Once the page is complete to get it into iPhoto as a jpeg file follow these steps:
    Here's how to get any file into iPhoto as a jpeg file:
    1 - open the file in any application that will open it.
    2 - type Command+P to start the print process.
    3  - click on the PDF button and select "Save PDF to iPhoto".
    NOTE:  If you don't have any of those options go to Toad's Cellar and download these two files:
    Save PDF to iPhoto 200 DPI.workflow.zip
    Save PDF to iPhoto 300 DPI.workflow.zip
    Unzip the files and place in the HD/Library/PDF Services folder and reboot.
    4 - select either of the files above (300 dip is used for photos to be included in a book that will be ordered).
    5 - in the window that comes up enter an album name or select an existing album and hit the Continue button.
    That will create a 200 or 300 dpi jpeg file of the item being printed and import it into iPhoto. For books to be printed choose 300 dpi.

  • Why am I having trouble importing vCards? I follow the Help Center instructions by dragging and dropping, but some don't sync into the cloud. And why can't I drag multiple vCards? I have over 4,000. Please tell me I don't have to do one at a time?

    Why am I having trouble importing vCards? I follow the Help Center instructions by dragging and dropping, but some don't sync into the cloud. And why can't I drag multiple vCards? I have over 4,000. Please tell me I don't have to do one at a time?

    carolinechx wrote:
    i know the description may be a little bit too confusing
    Mostly because you are not using any capital letters or paragraph returns and your post is difficult to read.

  • Drag and drop to photo shop no longer works after installing Apple "Photos"; It was working fine before the latest Apple update (10.10.3) . what can be done?

    drag and drop to photo shop no longer works after installing Apple "Photos"; It was working fine before the latest Apple update (10.10.3) . what can be done?

    Nothing. It's nothing to do with PSE; this is a limitation of Photos, as is the loss of being able to use an external editor without exporting copies of your images.

  • Drag and drop does not work in Exported release build

    I am using the built in DragManager class to handle some drag and drop functionality in an application.  When running from flex builder, It runs exactly as expected, but when I export the project to a release build, Dragging only works in the vertical direction.  How is this possible?  What might be causing such strange behavior.
    Any help would be much appreciated.

    Sorry, I will try to be more clear.  I am using drag and drop simply to move items around on a Canvas.  This works perfectly when running from flex builder, but when i export a release build it starts behaving strangely.
    I can drag items up or down on the canvas no problem, but as soon as I try to drag items left or right, there is no response.  On a windows machine, it gives me the black circle with a slash through it icon, implying that the drag is not accepted.  On Mac, there is no icon, it simply will not drag. 
    Hope that clarifies it, I could really use some help figuring this issue out.
    Update:
    I can confirm that the call to DragManager.acceptDragDrop is being reached in both cases, but the DragEvent.DRAG_DROP event is not being handled in the release build, (it is reached when run from flex builder)

  • Unable to share, export or drag and drop

    iPhoto Application (problems just started)
    1)Can't drag and drop from library to desk top
    2)Unable to share or export
    3)If library photo is double clicked I get a black frame with a "caution" symbol with ! point in center
    4)In the picture menu bar there are framed pictures as well as black frames with a dashed white square symbol in center
    What has or is happening? Is there any way to correct problem?
    Had a recent diagnosis done on IMac. Was told failing power supply and failing hard drive. Have replaced the power supply.
    Is above indication of failing hard drive?
    Thanks to the Community in advance

    Unlikely.
    This is a problem in the LIbrary and not the application. So reinstalling is unlikely to have any effect.
    Try rebuild the Library.
    Download iPhoto Library Manager and use its rebuild function. (In Library Manager it's the FIle -> Rebuild command)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  

  • Drag and Drop to Desktop Export

    In version 1.5, Aperture was capable of a 'drag and drop to desktop' JPEG export feature. This was very useful as it dramatically reduced the size of the file and maintained the fidelity of the image. However, Aperture 2.0 reduces the file size and dimensions. I would like the original dimensions but a reduced file size without using the Export feature. Any Suggestions?

    Hi,
    I have a similar question. I've noticed, when I drag a photo straight out of Aperture 2 to the Desktop, the file on the desktop takes on some interesting properties. For example, the original photo in Aperture is 4000 pixels in width, but if I drag it to the desktop, the copy it makes is 2000 pixels.
    Also, the dragged/copied version automatically gets an Adobe RGB (1998) ColorSync profile. I don't want it getting/using this profile, I want it using sRGB.
    There doesn't seem to be any control at all over the size and ColorSync profile of the dragged/copied image.

Maybe you are looking for