• Post Reply Bookmark Topic Watch Topic
  • New Topic

Drag & Drop problem  RSS feed

 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a question on DnD. the code first:

To reproduce you need to for instance grab a file on the desktop and try to drop it on the list.
The problem is that I get "java.awt.dnd.InvalidDnDOperationException: No drop current" (on the console) in the (probably) last* invocation of the canImport() method. If I remove retrieving the data from canImport(), it pretty much works, but... I need to take the data in canImport() as I want to check if the file list contains supported files (for example, check their extensions). If it does, I return true and the cursor shows that drop is available; if not, false is returned and the cursor shows the user that no drop can happen here. And I can do this only by analyzing the data. If I only check the DataFlavor, and get the data in importData(), it is possible that the cursor will show that drop is available even when the files are invalid, and on importData() it will turn out it is not possible and nothing will happen. This is not exactly the user experience I am striving for. This doesn't result in an exception, though.

Can anyone help me with this? What I want to achieve is a DnD process which shows the correct cursor to reflect the drop availability, and no exception of course ;d

Best regards,
Raf

* the Javadoc for TransferHanler.canImport(TransferSupport.TransferSupport) says that the canImport() method is called for the last time just before the importData() method is called. I think the exception happens just then, since if you grab a file and drag it over the list, and never drop, the methods simply succeed, which can be seen as a growing number is output to the console (the i counter variable).

P.S. This code shows the problem only under Windows. Under Linux (at least when Gnome is used) DataFlavor.javaFileListflavor is not supported, and DataFlavor.stringFlavor (or any other string flavors) must be used. The data that it holds is a newline delimited list of file URIs (in the way of fle://home/raf/Desktop/file.txt). This code under Linux will simply always return false. I didn't include the code here as it would take a little too much space. Anyways, when the DataFlavor (and the cast) is changed appropriately, the error will be the same.
 
Reyada Wolak
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm facing the same thing. any hint of what could be the problem. i tried this on two machines (Windows 7 32 and 64 bit). it happens on the 64bit only.
 
Reyada Wolak
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is a bug (or semi bug!):
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6759788
 
Esteban Nunez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey there! how are you doin? i guess its part of the same issue, but with a simple piece of code even JFormattedTextField default drag and drop behaviour fails on windows vista and 7 both 32bit, but it works under linux (ubuntu 10.04 x64).

i just put a JFormattedTextField in a JFrame, run it, then try to drag an image file from desktop to the JFormattedTextField but in windows it refuses to receive it. Under my ubuntu linux it receives the image and puts a text with the file path.

hope we found a solution. saludos desde mexico!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!