Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

cant convert an object to a transferable object?

Thread view: 
6e - 24 Oct 2005 16:38 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.