Drag and Drop Issues w/custom data type

L

Lizard

OK

I have a JList, whose ListModel is a list of a class specific to my
app, with a toString() method so it displays properly. I have a custom
component which draws these objects in an appropriate fashion. I want
to drag from the JList to this object.

Now: I have the basic DnD working -- I can currently drag from the
list to the object and have something happen. Currently, though, all I
can access is the standard text dragging.

I understand I need to add a Transferable or a Dataflavor or something
to handle dragging a serializable object type, but I am lost in a maze
of twisty little APIs, all alike. Can anyone provide a simple
step-by-step sequence on how to get this working?

The list does not need to ever accept a drop; the other components
needs to accept only drops of the appropriate object type and never
needs to accept a drag.

I'm currently kludging it by having my form (on which both objects
reside) tell the receiving object what object was selected from the
list when the drop started, then, when the drop is complete, the
receiver uses that info to do its thing, ignoring the actual content
of the drop event. This is so painfully ugly I want to kill myself.
 
S

steve

OK

I have a JList, whose ListModel is a list of a class specific to my
app, with a toString() method so it displays properly. I have a custom
component which draws these objects in an appropriate fashion. I want
to drag from the JList to this object.

Now: I have the basic DnD working -- I can currently drag from the
list to the object and have something happen. Currently, though, all I
can access is the standard text dragging.

I understand I need to add a Transferable or a Dataflavor or something
to handle dragging a serializable object type, but I am lost in a maze
of twisty little APIs, all alike. Can anyone provide a simple
step-by-step sequence on how to get this working?

The list does not need to ever accept a drop; the other components
needs to accept only drops of the appropriate object type and never
needs to accept a drag.

I'm currently kludging it by having my form (on which both objects
reside) tell the receiving object what object was selected from the
list when the drop started, then, when the drop is complete, the
receiver uses that info to do its thing, ignoring the actual content
of the drop event. This is so painfully ugly I want to kill myself.

it depends on the platform, I had a hell of a job with mis-represented
objects being dropped on linux under KDE, specifically it insisted that
jpg's were text objects.

steve
 
N

Nigel Wade

Lizard said:
OK

I have a JList, whose ListModel is a list of a class specific to my
app, with a toString() method so it displays properly. I have a custom
component which draws these objects in an appropriate fashion. I want
to drag from the JList to this object.

Now: I have the basic DnD working -- I can currently drag from the
list to the object and have something happen. Currently, though, all I
can access is the standard text dragging.

I understand I need to add a Transferable or a Dataflavor or something
to handle dragging a serializable object type, but I am lost in a maze
of twisty little APIs, all alike. Can anyone provide a simple
step-by-step sequence on how to get this working?

The list does not need to ever accept a drop; the other components
needs to accept only drops of the appropriate object type and never
needs to accept a drag.

I'm currently kludging it by having my form (on which both objects
reside) tell the receiving object what object was selected from the
list when the drop started, then, when the drop is complete, the
receiver uses that info to do its thing, ignoring the actual content
of the drop event. This is so painfully ugly I want to kill myself.

Have you seen this tutorial?

http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html

It provides a basic introduction and explains the relevant terms and APIs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top