I tried to implement the same functions as yours and fell into the same exceptions when trying to get the transmitted data.
It is unclear if getTransferable fails due to the default FlavorMap created in %matlabroot%\sys\java\jre\...\lib\flavormap.properties (as indicated in the book by Yair Altman in the drag and drop section) or some another strange reason. In any case, I went through this dndcontrol file-sharing object that works like a charm for our purpose, controlling the transmitted data directly on the java side.
I got inspiration from this to write my own matlab proxy on top of java.awt.dnd.DropTarget , which is more general and closer to its java implementation node (i.e. it works just like a DropTarget java DropTarget , except that all data types have been converted to more standard and convenient Matlab types).
You can download my implementation from here:
And here is an example of use in order to do what you need (omit the Matlab axis from the explorer file):
% % PURPOSE: % % Show how to add drop support from file explorer to some matlab axis % % SYNTAX: % % [] = DropListenerDemo(); % % USAGE: % % Simply drop files from file explorer into displayed axis. % %% function [] = DropListenerDemo() %[ % Create a figure with some axis inside fig = figure(666); clf; axes('Parent', fig); % Get back the java component associated to the axis % NB1: See ยง3.7.2 of Undocumented Secrets of Matlab Java Programming % NB2: or use findjobj, or javaObjectEDT for drop support onto other component types jFrame = get(handle(fig), 'JavaFrame'); jAxis = jFrame.getAxisComponent(); % Add listener for drop operations DropListener(jAxis, ... % The component to be observed 'DropFcn', @(s, e)onDrop(fig, s, e)); % Function to call on drop operation %] end function [] = onDrop(fig, listener, evtArg) %
The object also supports capturing events DragEnter , DragOver , DropActionChanged , DragExit , so that you can customize all aspects of the drag operation. With little effort, it can also be expanded to support dragging and dropping images or dragging other types of data.
I hope you enjoy it and you find it common enough to think about other customs.