Swing, Drog and Drop, Transfer Handlers...

I am writing a game that involves dragging and dropping pegs into various holes. Right now I have a bunch of JLabels that act as bins and a bunch of JLabels that act as holes. All the JLabels have a TransferHandler of type icon set:
xxx.setTransferHandler(new TransferHandler("icon"));
The bins have a mouse listener set following the example for adding dnd to swing components without default dnd support:
MouseListener ml = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
JComponent c = (JComponent)e.getSource();
TransferHandler th = c.getTransferHandler();
th.exportAsDrag(c, e, TransferHandler.COPY);
binsxxx.addMouseListener(ml);
The transfer handler sets up both source and target capabilities, which I dont want for the bins so I created a DropTarget, disabled it and set the bins droptarget to that:
DropTarget dt = new DropTarget();
dt.setEnable(false);
binsxxx.setDropTarget(dt);
With these few snippets of code, I can drag a peg (an icon) from bin to hole.
Finally, onto my question. I know from browsing through he awt.dnd package that there is the capablity of adding an icon to follow the cursor on a drag event. Can I easily add this feature to my program without nullifying the default transferHandler behavior (ie requiring me to go and muck around with the awt.dnd stuff directly)?

I was wondering if you got to the bottom of this exception?
I'm implementing dnd between two JTrees in a splitpane & I'm seeing the same exception when the drag leaves a tree. Any suggestions would be greatly appreciated.
java.lang.NullPointerException
     at javax.swing.plaf.basic.BasicTreeUI$TreeDropTargetListener.restoreComponentState(Unknown Source)
     at javax.swing.plaf.basic.BasicDropTargetListener.dragExit(Unknown Source)
     at javax.swing.TransferHandler$SwingDropTarget.dragExit(Unknown Source)
     at sun.awt.dnd.SunDropTargetContextPeer.processExitMessage(Unknown Source)
     at sun.awt.dnd.SunDropTargetContextPeer.access$700(Unknown Source)
     at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchExitEvent(Unknown Source)
     at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(Unknown Source)
     at sun.awt.dnd.SunDropTargetEvent.dispatch(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)

Similar Messages

  • Swing drap and drop ?

    How can i make the act drap and drop in swing?

    Hi zhenglan!
    I found examples of Drag&Drop (for Swing) at:
    http://developer.java.sun.com/developer/codesamples/examplets/index.html
    Best Regards.

  • Muvo slim,What is displayed in window and does it use windows explorer drag and drop to trans

    Im about to buy a muvo slim and already own a zen xtra.Does muvo slim allow for recharge using plug accessory I got with my zen or can i only charge using usb cord and computer?What is displayed in screen and can i use drag and drop transfer method from windows explorer?Finally can i use the mediasource 3.20 softwear update i now use with my zen or must i input different mediasource version for slim than one i use with the zen? thanks matt

    mattg3 wrote:
    Im about to buy a muvo slim and already own a zen xtra.Does muvo slim allow for recharge using plug accessory I got with my zen or can i only charge using usb cord and computer?
    It charges via its USB socket, so you can't use the Xtra's power supply.
    What is displayed in screen and can i use drag and drop transfer method from windows explorer?
    It works as a flash dri've, so appears as a dri've letter in Windows Explorer.
    Finally can i use the mediasource 3.20 softwear update i now use with my zen or must i input different mediasource version for slim than one i use with the zen? thanks matt
    Go to Nomadworld.com downloads and you'll see the Slim listed there with MediaSource and the MuVo plugin.

  • How to drag and drop the af:inputNumberSpinbox in the control panel

    Hi,
    I am using jdev 11.1.1.4.0
    I need the component as <af:inputNumberSpinbox> . Create a data model and how to drag and drop as inputNumberSpinbox in the data control.
    normally drog and drop the particular attribute as inputText box only. I want <af:inputNumberSpinbox>.
    anythig want to change in the view object control hints itself. help me.
    Regards,
    ragupathi S.
    Edited by: Ragu on Jun 22, 2011 4:45 PM

    Hi,
    Can't you drop it as an inputText and then change it in the source to inputNumberSpinbox?
    Regards,
    Stijn.

  • Drag and Drop between two trees...

    Hi ,
    Please tell me how to drog and drop from two diffrient trees in a form?
    is the any demo for this one .. please let me know if there..
    thanks in advance
    Mani

    Mani,
    this is not possible. Drag and drop works in client-server and even there you can't drag and drop from one tree to another because a tree is an item on its own. You could decide to build your own tree in a Java Bean and then apply drag and drop to it. Its a non trivial task though.
    Frank

  • How to Drag and drop Between ALVs

    Hello Experts,
                    How to drog and drop from one alv to another alv. Is it possible? Please suggest me..
    Thanks.

    Hi Pankaj,
                Thanks for ur reply.I have two grids.The first grid have set of values.I want to drag selected entry in first grid to second grid. For example
    First grid             Second grid
    Value1
    Value2
    Value3
    First grid              Second grid
    Value1                     Value2
    Value3
    Is it possible?
    Thanks.

  • How do I transfer files/folders to an external hard drive without "dragging and dropping"?

    Hi, I'm having a lot of trouble trying to transfer folders of pictures and individual pictures to my external hard drive (which God forbid isn't an Apple product). I attempted to drag and drop, which usually works. I have also attempted to find an option in any drop down menu which will allow me to import/transfer/etc. the photos from my Macbook to the external hard drive. This is maddening because the hard drive was immediately compatible and I can see everything that's on it already, I just can't really do anything with the content going either way. Is it because I need to compress things? Something like that? Any help or insight would be greatly appreciated.
    Thanks,
    William

    William G 42 wrote:
    , I just can't really do anything with the content going either way.
    Make sure the EHD is Formatted Mac OS Extended (journaled
    Format, Erase, or Reformat a drive
    In iPhoto, Select All the Photos you want to move... Then Goto... > File > Export >
    Choose the settings as seen here
    Click Export and select your External Drive
    Best to create a Folder to put them in... and away you go...
    More Help available from iPhoto Toolbar Help Menu

  • I have a seagate 1tb hard drive and a 16gb memory stick, how do i transfer avi files from one to another as the click drag and drop wont work, please help?

    i have a seagate 1tb hard drive and a 16gb memory stick, how do i transfer avi files from one to another as the click drag and drop wont work, please help?

    Greetings,
    What happens when you drag it?
    Make sure the drive you are moving the files to has enough available space to receive the file:
    Click on the movie file and go to File >  Get Info and note the "size"
    Check the drive to which you are moving the file to make sure it has enough available space: https://idisk.me.com/madisonfile-Public/web/finder-drive-available-space-and-for mat.html
    Also note the format of the drive you are copying too.  If it is not Mac OS Extended or FAT (not recommended unless you are taking it to a windows computer) then that may be the issue.
    Hope that helps.

  • Hi could someone help me please ? Ive just bought the new ipad and want to put some movies on it. I have already converted some movies using handbrake and tried to transfer them to my ipad and it just wont work. ive tried drag and drop and everything

    Hi could someone help me please ? Ive just bought the new ipad and want to put some movies on it. I have already converted some movies using handbrake and tried to transfer them to my ipad and it just wont work. ive tried drag and drop and everything

    bluztoo wrote:
    Haven't really used any of them including VLC - actually use netflix on the ipad more than anything. I was able to drop an mp4 into imovie on my ipad and see it there. This was something I had shot as avhcd and converted with turbo.264. Played fine. Probably not what you want for a movie player though.
    Well, turbo.264 is indeed very nice to have - even for converting full-sized movies. (Nevertheless, TechRadar's latest roundup (see http://www.techradar.com/news/software/applications/6-of-the-best-video-converte rs-for-mac-1074303 ; also linked from another roundup at http://www.iphonelife.com/blog/87/benchmark-excellent-multimedia-converter-handb rake-vs-commercial-apps ) has shown it's still worse than HandBrake in most respects.)
    All H.264 files (assuming they are H.264 level 4.1 or lower) are compatible with the built-in Videos app.
    bluztoo wrote:
    Those of you who use other players, what do you reccomend? Just curious.
    It entirely depends on your needs. The top players (AVPlayerHD / ProPlayer, It's Playing, GoodPlayer) all have different strengths and weaknesses. I myself use It's Playing the most as I convert everything into MP4 and simply love the DSP's (brightness / volume / saturation boosting). (Its software decoders are definitely worse than those of AVPlayerHD / ProPlayer; however, MP4's are played back from hardware.)

  • When I try to drag and drop my photos in iPhoto to an external drive (for backup or to transfer them to my other Mac) only some will transfer.  If I copy

    When I try to drag and drop my photos in iPhoto to an external drive (for backup or to transfer them to my other Mac) only some will transfer.  If I copy and paste, the same thing happens.  The photos are all taken with the same camera, but some will not transfer.  It tells me right away - for example, I'll "grab" 3500 photos to drag and move, and the red ball will tell me it's moving 3256 or something.  If I use the copy function instead - copy 3500 photos, it will show in Finder that I can paste 3256 or whatever. This happens on my iMac as well as my MacBook Pro.  It started recently and I've never had this before.  Any thoughts?  Thank you!

    Are you able to use the File ➙ Export ➙ File Export menu to export  the photos into a folder on the EHD?
    OT

  • I cannot transfer purchased music from pc to iphone 4. Will not let me drag and drop.

    I purchased an album and downloaded to my itunes on my pc. I cannot get it to transfer (copy) to my iphone 4. It will not drag and drop nor will it copy and paste. Any solutions.

    You sync it as you do everything else.
    Open itunes, connect iphone, select what you want to sync, sync.
    If you want to drag and drop you would have to select manually manage music.
    Maybe you should read the manual.

  • Drag and Drop files from website to local swing application

    I want to drag some file from the web browser and drop that to local swing list. Please suggest something on that?
    Regards,
    Kanni

    Kanni wrote:
    Can we do this using dnd, from a website.Yes.
    Can you pass me some sample code.No.

  • How can I learn "Drag and Drop" with Swing components?

    Hello,
    Im using swing components, so using paint() to draw a "drag icon" doesnt seem acceptable. Im basically trying to move a JPanel image to be dragged/dropped over another JPanel in the same program/applet.
    I looked at Sun's Java Tutorial for information on doing drag and drop, but there was no trail completed yet.
    Does anyone know of any good resources to learn? Or can at least give me a general idea of how to do drag and drop?

    Did you see this?
    http://java.sun.com/docs/books/tutorial/dnd/index.html
    http://java.sun.com/docs/books/tutorial/reallybigindex.html

  • Hi, im currently using an windows 8 computer and have installed itunes 11.5. My problem is i'm trying to transfer one song from my computer to my iphone. But some how i cannot drag and drop like last time itunes 10.x.

    Hi, im currently using an windows 8 computer and have installed itunes 11.5. My problem is i'm trying to transfer one song from my computer to my iphone. But some how i cannot drag and drop like last time itunes 10.x. I do not wish to sync as it means of deleting my entire song list from my phone just to transfer 1.

    " I ordered the Snow Leopard software and tried installing it, but it stopped and said to clean the disk."
    First off, your installation disc is in all likelihood faulty.
    This has been a known issue in the past:
    Faulty Snow Leopard install discs - Apple has no timeline on ...
    http://store.apple.com/us/help/returns_refund#policy:
    *You can return software, provided that it has not been installed on any computer. Software that contains a printed software license may not be returned if the seal or sticker on the software media packaging is broken.

  • Hi, this is my first time to encounter this problem. Whenever i try to sync my songs from my PC to my Ipod, it doesnt seem to respond. When i drag and drop it, it hangs and could not transfer it. Please delp me... Thanks a bunch! :)

    Hi, this is my first time to encounter this problem. Whenever i try to sync my songs from my PC to my Ipod, it doesnt seem to respond. When i drag and drop it, it hangs and could not transfer it. Please help me... Thanks a bunch! :

    Your post is difficult to read and looks like one solid block of text...
    Some very useful Info here with regard to Photo syncing and iOS Devices...
    http://support.apple.com/kb/HT4236

Maybe you are looking for

  • Develop settings not showing up in library module view of image

    Hi there A quick question about an issue I have not seen before.  Imported a raw image .cr2 file from a Canon S95.  Opened develop module and applied clarity, vibrance and sauration adjustements.  Clicked back to Library module and the adjustments ha

  • Problem with the "now playing"-function after timer sleep-mode

    At first: sorry for my english. I have the following problem with the Nano 6G: I set the timer of my iPod Nano to shut it down after a while of playing. When I turn it back on afterwards, the now-playing-button does not show the song that it played a

  • Cannot mount dvd or usb flash drive in kde 4.6 ?

    Hi, I am unable to mount a dvd in kde 4.6 I keep getting the following error: udisk error permission denied: not authorised I have added myself to storage, disk and all the normal groups. I had the same problem with a flash drive but after adding the

  • My toolbars don't work in CS5 InDesign.

    When I open InDesign, I can't get the toolbars to work (the ones along the left as well as the varioius Type and other tool bar icons across the top. I tried removing my preferences, but that didn't work.

  • Attachments to Winmail Won't Open

    PDF docs attached to incoming Winmail messages will not open when clicked.  The error box comes up claiming there is no program associated with this type of file and to go create an association. I have done that numerous times, have reloaded Adobe re