Welcome to Dream.In.Code
Become a Java Expert!

Join 150,375 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,684 people online right now. Registration is fast and FREE... Join Now!




Dragging files to a program

 
Reply to this topicStart new topic

Dragging files to a program

Techno Mage
17 Feb, 2008 - 06:20 AM
Post #1

D.I.C Head
**

Joined: 10 Jun, 2007
Posts: 61


My Contributions
A few times, I've seen programs where, instead of clicking on it to make it work, you click and drag a file on top of its icon and it does the work. How could I do this in Java?
User is offlineProfile CardPM
+Quote Post

dontKnowJava
RE: Dragging Files To A Program
17 Feb, 2008 - 08:51 AM
Post #2

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
try MouseEvent and MouseListener classes when file coordinates = icon coordinates you start your program
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Dragging Files To A Program
17 Feb, 2008 - 09:53 AM
Post #3

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
I think it is an OS feature, and it calls your program with the dragged file as a parameter. So its path and name should be received as a command line argument. I haven't looked into it, but that is my guess (maybe some other configuration is needed).
User is offlineProfile CardPM
+Quote Post

Tom9729
RE: Dragging Files To A Program
17 Feb, 2008 - 11:49 AM
Post #4

Debian guru
Group Icon

Joined: 30 Dec, 2007
Posts: 1,592



Thanked: 12 times
Dream Kudos: 325
My Contributions
http://java.sun.com/docs/books/tutorial/ui.../dnd/intro.html
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Dragging Files To A Program
17 Feb, 2008 - 12:18 PM
Post #5

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
I think that he is not looking for dragging a file onto a Java window, but dragging a file onto the Java program in windows, so the java program is launched and it uses the dropped file as input.

User is offlineProfile CardPM
+Quote Post

Tom9729
RE: Dragging Files To A Program
17 Feb, 2008 - 01:00 PM
Post #6

Debian guru
Group Icon

Joined: 30 Dec, 2007
Posts: 1,592



Thanked: 12 times
Dream Kudos: 325
My Contributions
QUOTE(1lacca @ 17 Feb, 2008 - 01:18 PM) *

I think that he is not looking for dragging a file onto a Java window, but dragging a file onto the Java program in windows, so the java program is launched and it uses the dropped file as input.

http://www.java2s.com/Code/Java/Swing-JFC/...DropTarget2.htm
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Dragging Files To A Program
17 Feb, 2008 - 02:58 PM
Post #7

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
I know DnD in Swing, what I am trying to get through, is that he wrote that he would like to drag the other file onto the ICON of his program, so I suppose that it is NOT RUNNING when he drops the file onto it. Swing DnD simply won't do anything in this situation.
However in windows it is possible to drag a file onto the ICON of a console program that does not have ANY WINDOWS, and it will take it as input (I think the Lame mp3 encoder had a command line version that worked like this if you dragged a wav file onto it, it converted it to mp3).
Anyway I think we have to wait for the poster to clarify his intentions.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:54PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month