Java JFileChooser drag n drop (dnd) does not work on the Mac

Discussion in 'Mac Programming' started by djangohead, Jan 5, 2010.

  1. djangohead macrumors newbie

    Jan 5, 2010
    I am trying to create an uploader applet using JFileChooser for file selection. I want the user to be able to drag files from JFileChooser into another component.

    I have this code working in Windows but the drag event is simply not registering on the Mac. Left click and drag down simply selects all the the directories/files within the current directory. Is this a bug related to Apple's implementation of Java, or Apple's custom implementation of JFileChooser? I can get drag/drop events to work using any other component, just not JFileChooser.

    Any help on this issue is a massive help as I cannot find anything related to the problem I'm having after searching on the net.


    Mac OS X Snow Leapord Version 10.6.2

    java version "1.6.0_17"
    Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-10M3025)
    Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode)

    Thank you
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    That doesn't sound like a Mac gesture. I just tried it using the native dialogs in TextEdit and several other apps, and no combination of clicks and modifier keys was able to start a drag.

    It seems that the inability to drag files out of a file-chooser isn't just Java. You may have to rethink your strategy.

    EDIT: I take it back. It can do a drag out in native dialogs. It only starts a drag when the click is on an unselected item, and if movement starts within a brief interval.

    Still no-go in Java file-chooser though. Try an AWT FileDialog instead, or rethink your strategy.
  3. Transporteur macrumors 68030

    Nov 30, 2008
    Yes, FileDialog does the job and is definitely the way to go on the Mac to get the look and feel of native OS X apps.
  4. wrldwzrd89 macrumors G5


    Jun 6, 2003
    Solon, OH
    If you happen to need file type filters (which don't work in FileDialogs), AND need a native look and feel, give the Quaqua library a try. I use it for my Java development.
  5. Transporteur macrumors 68030

    Nov 30, 2008
    Nice find. Thanks for that!

Share This Page