Hi,
Im trying to implement the drag on drop example presented on
www.javaworld.com/javatips/jw-javatip97_p.html
in my own application.
The weird thing is that in my application I cannot get the object to
convert to a transferable object, while in the example it actually does
work...
It seems like such a silly problem, but Ive noticed on other forums
similar questions posted without answers. So I was wondering if one of
you could shed some insight into the situation.
The getUserObject() returns a defaultMutableTreeNode Object...
Object x = dragNode.getUserObject();
Transferable transferable = (Transferable) x;
Thomas Fritsch - 24 Oct 2005 17:11 GMT
> Im trying to implement the drag on drop example presented on
> www.javaworld.com/javatips/jw-javatip97_p.html
[quoted text clipped - 12 lines]
> Object x = dragNode.getUserObject();
> Transferable transferable = (Transferable) x;
I don't know what is the class of your object x, but probably it does
not implement the Transferable interface.
You would be lucky if x is a String. Then you can do
Transferable transferable = new StringSelection((String) x);
or
Transferable transferable = new StringSelection(x.toString());
(StringSelection is the Transferable-implementation for transferring a
String.) In all other cases you would have to develop your own
implementation of Transferable.

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
6e - 24 Oct 2005 18:23 GMT
it does "implements Transferable"...
Roedy Green - 25 Oct 2005 05:23 GMT
>Object x = dragNode.getUserObject();
>Transferable transferable = (Transferable) x;
To experiment to see what is happening we need your complete code,
preferably pruned of all irrelevancies.
You could find out what getUserObject is giving you like this:
System.out.println( x.getClass() );
That class has to formally implement Transferable, not just have the
methods.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.