my dog learned polymorphism*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

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) {
event.acceptDrop(DnDConstants.ACTION_COPY);

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) iterator.next();
browserPane.goToURL(file.toURL());

}
event.dropComplete(true);
}

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
Anu
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Drag and Drop problem with Images (*.jpg & *.gif)
 
Similar Threads
Cannot get TransferHandler to work in Swing
Drag and Drop from JList to JTable.
drag & drop issue on Mac
problem while pasting images on to the java application from Mac Systemclipboard
drag & drop issue on Mac