This subject is a few weeks old, but I figured out the solution that
Glen was referring to below in his response and thought I would post
it.
David Daniel wrote:
| After much ado, I finally have dnd working, dragging a subclass of a
| JComponent that custom draws an image representing the component
| between JFrames. However, what now appears to be an *erroneous*
error
| message had led me to believe that the code generating the error
| message was the reason my dnd wasn't working previously, when there
| were actually other problems with my code - that is, while the dnd
now
| works, I still get the exact same error message whenever I start a
| drag, which is:
|
| java.lang.ClassCastException
| at
|
sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransfere
r
| .java:1189)
| at
| apple.awt.CDataTransferer.translateTransferable(CDataTransferer.java:
| 125)
| at
sun.awt.datatransfer.DataTransferer$5.run(DataTransferer.java:2018)
| ... [more lines deleted] ...
|
| So question #1: Has anyone seen this exception thrown erroneously or
| inconsequentially? Or, could this still be a real problem with my
code
| although it now seems to work fine?
I tracked down something like that long ago. The problem turned out to
be that the code expected the dragged object to be an InputStream (I
think it was) containing the serialized representation of the dragged
value. I don't recall the specifics anymore, nor what part of the code
expected a stream, but *giving* it a stream made the message go away.
(I believe there was a way to persuade it *not* to expect a stream,
but the details are lost in the mists of time.)
The default representationClass for a DataFlavor is InputStream, which
is what was causing the error message to be generated. Hence, in the
class implementing Transferable, one needs to ensure that the
representationClass for a DataFlavor is explicitly something else.
Below is the code I used in my Transferable that resolved the reported
error. Thanks for the tip, Glen.
static public DataFlavor WMOFlavor;
private DataFlavor[] flavors = {WMOFlavor};
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden