DragNDrop from Java to Windows Explorer

南笙酒味 提交于 2019-12-10 23:46:32

问题


I want to create an application in Java that lists a directory and add drag and drop support to it for copying files from that directory to the explorer window opened and vice-versa(Windows system).

While adding support to drag and drop from windows explorer to the java application is quite easy, it kind of eludes me how to do it when the action starts from the java application and ends in explorer.

I tried searching google and SO, but to no avail.

Any pointers, directions, snippets of codes or pseudocodes will be appreciated.

So, is it possible to drag from a java application and transfer data to a drop target in a native application? If yes (it should be), can you point me in the right direction?


回答1:


Yes, what you have to do is set the mime type on the transferable, and set the accepted actions (i.e. copy, move, etc) as well as the default action (it sounds like a copy action for what you are trying to do). This class is the transfer handler, which is what is used to handle DnD in Swing.




回答2:


Just use the fileListFlavour DataFlavour and File drag'n drop will "just work" in both directions.

I'm sure you found the section on drag n drop in the java tutorial.




回答3:


Book: Swing Hacks Hack # 65 That's your answer :)



来源:https://stackoverflow.com/questions/1381539/dragndrop-from-java-to-windows-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!