File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Drag and Drop problem with Images (*.jpg & *.gif) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drag and Drop problem with Images (*.jpg & *.gif)" Watch "Drag and Drop problem with Images (*.jpg & *.gif)" New topic

Drag and Drop problem with Images (*.jpg & *.gif)

Anu Sri
Ranch Hand

Joined: Jul 29, 2002
Posts: 43
Hi All
Please help me with following problem. I am having a problem with Images needs to be transfer from Explorer to the WebPane. I can able to copy file( mean .doc file and .txt and .html files). But i have to copy oly image file (*.jpg & *.gif) files only. I am just entering what I wrote for files here, Please let me know what I need to modify.

private class DropTargetHandler implements DropTargetListener {

public void drop ( DropTargetDropEvent event ){

Transferable transferable = event.getTransferable();

if( transferable.isDataFlavorSupported( DataFlavor.javaFileListFlavor ) ){
// if ( (DataFlavor.javaFileListFlavor).equals(DataFlavor.imageFlavor))(This I wrote for first image file) {

try {
java.util.List fileList = (java.util.List) transferable.
getTransferData(DataFlavor.javaFileListFlavor )

//java.util.List fileList = (java.util.List) transferable.
getTransferData(DataFlavor.imageFlavor);(This is what I wrote for Imagefile by replacing the above)

Iterator iterator = fileList.iterator();

while (iterator.hasNext()) {

File file = (File);


After this I did catch exception like that.

PLease let me know what I need to change in the above code for getting ONLY IMAGES (*.gif & *.jpg) HAS TO BE DROPPED.

Thank you
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

I'm going to move this to the Swing/AWT forum to see if you can have some better luck over there.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Drag and Drop problem with Images (*.jpg & *.gif)
jQuery in Action, 3rd edition