Drag and Drop Issues w/custom data type

Discussion in 'Java' started by Lizard, Aug 9, 2006.

  1. Lizard

    Lizard Guest

    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.
    Lizard, Aug 9, 2006
    #1
    1. Advertising

  2. Lizard

    steve Guest

    On Thu, 10 Aug 2006 04:01:20 +0800, Lizard wrote
    (in article <>):

    > 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
    steve, Aug 9, 2006
    #2
    1. Advertising

  3. Lizard

    Nigel Wade Guest

    Lizard wrote:

    > 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.

    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
    Nigel Wade, Aug 11, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oliver Klein
    Replies:
    0
    Views:
    675
    Oliver Klein
    Aug 24, 2003
  2. Mudcat
    Replies:
    2
    Views:
    967
    Mudcat
    Dec 14, 2008
  3. Andrea Williams

    Custom control won't drag and drop to page

    Andrea Williams, Mar 29, 2005, in forum: ASP .Net Building Controls
    Replies:
    10
    Views:
    247
  4. Khoi Pham

    drag and drop in a custom web control

    Khoi Pham, Jul 30, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    170
    Alvin Bruney
    Jul 31, 2003
  5. Gilles

    Drag & Drop custom control

    Gilles, Feb 1, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    157
    Gilles
    Feb 1, 2005
Loading...

Share This Page