Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Java drag & drop

Subject: Java drag & drop

From: Malcolm Lidierth

Date: 22 Aug, 2007 15:51:14

Message: 1 of 6

Here are two attempts to implement drop & drag. The second
method is successful in invoking the callback, but access
to hObj and EventData (e,g, through get) then cause
exceptions. Does anyone (are you there Yair) have any ideas?

function droptrial()
f=figure();
j=javacomponent('javax.swing.JComboBox',[],f);
j.setEditable(true);
e=get(j.Editor,'EditorComponent');

% METHOD 1
% This produces an exception and fails:
dnd=e.getDropTarget();
set(dnd, 'DropCallback', @MyCallback);

% METHOD 2
% This works but calls like get(hObj) produce exceptions in
the callback
dnd=java.awt.dnd.DropTarget();
set(dnd, 'DropCallback', @MyCallback);
e.setDropTarget(dnd);
return
end

function MyCallback(hObj, Ev)
get(hObj);
return
end

METHOD1 produces
java.lang.IllegalAccessException: Class
com.mathworks.jmi.bean.MatlabBeanInterface can not access a
member of class javax.swing.TransferHandler$SwingDropTarget
with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess
(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
com.mathworks.jmi.bean.MatlabBeanInterface.addCallback
(MatlabBeanInterface.java:691)
at
com.mathworks.jmi.bean.MatlabCallbackInterface.addCallback
(MatlabCallbackInterface.java:128)


METHOD2, when get(hObj) is called from the callback after
making a drop (from a JTree) produces
K>> get(hObj)
Active = on
Class = [ (1 by 1) java.lang.Class array]
Component = [ (1 by 1)
javax.swing.plaf.metal.MetalComboBoxEditor$1 array]
DefaultActions = [3]
DropTargetContext = [ (1 by 1)
java.awt.dnd.DropTargetContext array]
FlavorMap = [ (1 by 1)
java.awt.datatransfer.SystemFlavorMap array]
DropCallback = [ (1 by 1) function_handle array]
DropCallbackDatajava.lang.reflect.InvocationTargetEx
ception
at sun.reflect.NativeMethodAccessorImpl.invoke0
(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mathworks.jmi.bean.ClassInfo.getObjectField
(ClassInfo.java:323)
Caused by: java.awt.dnd.InvalidDnDOperationException: The
operation requested cannot be performed by the DnD system
since it is not in the appropriate state
at java.awt.dnd.DropTargetContext.getTransferable
(Unknown Source)
at java.awt.dnd.DropTargetDropEvent.getTransferable
(Unknown Source)
... 5 more

Subject: Java drag & drop

From: Yair Altman

Date: 22 Aug, 2007 21:01:45

Message: 2 of 6

I must admit I'm just as baffled. It appears that
e.setDropTarget() overrides the default call to the drop
target's TransferHandler() method (which is the default text
handler
javax.swing.plaf.basic.BasicTextUI$TextTransferHandler). You
might try to implement your own TransferHandler as explained
here:
http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html
. I believe R2007b (Matlab 7.5) uses Java 1.6 and if so,
then you may be interested in the following article:
http://weblogs.java.net/blog/shan_man/archive/2006/02/choosing_the_dr.html

Yair Altman
http://ymasoftware.com

Subject: Java drag & drop

From: Malcolm Lidierth

Date: 23 Aug, 2007 13:08:06

Message: 3 of 6

Dear Yair
Many thanks.
The R2007b pre-release produces identical exceptions but
thanks for the links. I think your suggestion is on the
right lines: the problems in the callback seem to arise
through calls to DropTargetDropEvent.getTransferable().
I'll follow the links and try TMW with a service request.
ML

Subject: Java drag & drop

From: Raphael Austin

Date: 11 Sep, 2007 14:20:57

Message: 4 of 6

I've posted a drag and drop example, but using Activex.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile
.do?objectId=16312&objectType=file

<a
href="http://www.mathworks.com/matlabcentral/fileexchange/lo
adFile.do?objectId=16312&objectType=file">
http://www.mathworks.com/matlabcentral/fileexchange/loadFile
.do?objectId=16312&objectType=file </a>

Subject: Java drag & drop

From: Malcolm Lidierth

Date: 12 Sep, 2007 15:45:49

Message: 5 of 6

Thanks Raphael. Unfortunately, I need a platform-
independent method.

For those interested TMW Support have just sent this to
Development as a bug notice.

I have found a workaround for my specific needs but not a
proper one. Might the drop event have been handled/rejected
in a listener before the callback is activated?

Subject: Java drag & drop

From: Malcolm Lidierth

Date: 12 Sep, 2007 16:23:45

Message: 6 of 6

I should have added:

dnd=java.awt.dnd.DropTarget();
dnd=handle(dnd,'callbackProperties')

at least lets you get(hObject) in the callback as long as
you do not call hObject.getTransferable()

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
activex Raphael Austin 11 Sep, 2007 10:25:05
dnd Raphael Austin 11 Sep, 2007 10:25:05
drag drop Raphael Austin 11 Sep, 2007 10:25:05
dd Malcolm Lidierth 22 Aug, 2007 11:55:06
java Malcolm Lidierth 22 Aug, 2007 11:55:05
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics