Question

I am trying to create a program were the user drags a file into an area (currently a JTextArea, but can be another container) and it adds the absolute path of the file to an ArrayList. I am having trouble figuring out how to implement drag and drop of files.

so far I have tried reading some similar questions but they aren't really helping me. (also this is targeting windows but linux/mac support is an option as well)

Was it helpful?

Solution

Have a look at oracles page about DnD. Basically you can drag everything into your program, should it be a file directly from a native browser or the JFileChooser. What you are dragging is only the path to the file. So you only have to set your JTextAreato accept drops and define how it has to "interpret" the object that was being dropped.

OTHER TIPS

Here is a full blown example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top