-1

I have a problem, and don't know where start. I want to drop files (only .zip) from any place in windows into a Swing application (into a JList). How can I do this?

In the list I will display only absolute path, and file may be in array or something like that. Java 1.6

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Gwalk
  • 211
  • 4
  • 13
  • 4
    Google Java Swing drag-and-drop, and prepare to do a lot of reading/studying on the subject, since it isn't fully straightforward how to use. – Hovercraft Full Of Eels Nov 20 '14 at 21:37
  • 1
    For [example](http://stackoverflow.com/questions/13597233/how-to-drag-and-drop-files-from-a-directory-in-java/13597635#13597635), [example](http://stackoverflow.com/questions/13639804/drag-and-drop-files-from-os-into-jtable-java/13640115#13640115), [example](http://stackoverflow.com/questions/15080244/java-drag-n-drop-files-of-specific-extension-on-jframe/15080654#15080654) – MadProgrammer Nov 20 '14 at 23:23

2 Answers2

2

One could try to implement that oneself, but as the comment from Hovercraft Full Of Eels mentions there are many caveats to take care of.

I personally use the code I found here: http://iharder.sourceforge.net/current/java/filedrop/

It is a simple java class FileDrop which deals with all the special cases that can occur, and provides an easy interface for dealing with dropped files. The class is public domain and thus free to use for any purpose.

cello
  • 5,356
  • 3
  • 23
  • 28
2

The keyword you are missing is TransferSupport

https://docs.oracle.com/javase/tutorial/uiswing/dnd/transfersupport.html

https://docs.oracle.com/javase/tutorial/uiswing/dnd/dropmodes.html

But basically you have to make a TransferHandler which has methods to import data via drag and drop. But you have to transform the data into whatever you want (in your case take the File (probably as a DataFlavor#javaFileListFlavor) and convert them to paths

https://docs.oracle.com/javase/tutorial/uiswing/dnd/dropmodedemo.html

dkatzel
  • 31,188
  • 3
  • 63
  • 67