• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Drag and Drop/Transfer handling help

 
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I am trying to set up a way to drag items from a list onto a panel or frame... I am using Netbeans so the list has 5 items, and I have set drop to be enabled on it. I am trying to set up the TransferHandler and DropTarget... There is a lot of methods and I'm not really sure how to go about this. I'm reading the Oracle Trail http://docs.oracle.com/javase/tutorial/uiswing/dnd/transferhandler.html and so far it seems like I need to set the source and stuff for the export(which is already set up it seems when I click "dropEnabled" in the gui), but now I need to setup the transfer to be imported....

So far I have this

But I'm not sure if I set that up right....

Let me know if this code is wrong and where I need to change it... I would appreciate any input, and I will be editing this as I try to do this myself...

Thanks ,

~JO
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the tutorial that you are reading, in this page, it is clearly mentioned that the default TransferHandler is not enough for lists, tables & trees. In the subsequent pages, it is clearly shown which methods need to be overridden. You have not done that. Also, you are using the new TransferHandler("t") - did you read the API to see what this constructor means?
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ranganathan Kaliyur Mannar wrote:In the tutorial that you are reading, in this page, it is clearly mentioned that the default TransferHandler is not enough for lists, tables & trees. In the subsequent pages, it is clearly shown which methods need to be overridden. You have not done that. Also, you are using the new TransferHandler("t") - did you read the API to see what this constructor means?



I've read the tutorial, but I'm confused exactly what is needed to be done. There are like 5 classes that are used to support it, I'm not really sure how to go about what I need to.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But if the tutorial is the same as when I went through it (a few years ago) then it has sample code. I would suggest downloading and running that code, and then fiddling with it until it turns into the code which you need. That would have been what I did at the time.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:But if the tutorial is the same as when I went through it (a few years ago) then it has sample code. I would suggest downloading and running that code, and then fiddling with it until it turns into the code which you need. That would have been what I did at the time.



Yeah it does, I was reading it when I posted this, but was confused on what classes I would need, it seems like TransferHandler needs a support, and then a dataFlavor if not a normal one(in this case I have to make it based on a class I created called face) and then a transferable object.... I'm not sure if there is any more, but I'm just overall confused with what I need to do I guess...

What I need to do is be able to take an object from a custom JList that will have a set of image boxes and aname where when I drag it from my JList to a Display Panel it will drag the outline of the object, and then release the item and create a new Element in an Array of Faces. I also need to do the same thing with a JList that has the text for the item.

I'm not sure where to start, any direction and what classes I might need would be appreciated. So far it seems I only need the 4 I mentioned...

Thanks,

~JO
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But the BasicDND example in the tutorial does include dragging from a JList. I just went and had a look. So again, I would recommend starting from that. You are looking at Oracle's tutorial, aren't you?
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not clear to me what the problem is. As Paul has pointed out, the tutorial's first example has JList in it. Plus, you can even launch it via JWS to see a live demo of drag-drop in JList. If your JList has a custom class, you need to create the appropriate DataFlavor and TransferHandler class for that. I think the object being dragged is the actual object and not the one shown by the renderer.

Why don't you ShowSomeEffort by starting to write the program with whatever you have read? And then post the code back if you are stuck.
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:But the BasicDND example in the tutorial does include dragging from a JList. I just went and had a look. So again, I would recommend starting from that. You are looking at Oracle's tutorial, aren't you?



Yeah, actually I forgot I could check out the code examples, thanks this is very helpful.. I also found out there is a section in the API call "use" that shows all the uses of a certain class, very helpful....

1 question though for creating a DataFlavor it says in the tutorial you can do DataFlavor(class, string); or DataFlavor(class[], string). What exactly does the array version do differently? Can you only use the dataflavor once without the array or...?


Also how do you set the DataFlavor for a component is it this :

canImport(JComponent comp, DataFlavor[] transferFlavors)
Indicates whether a component will accept an import of the given set of data flavors prior to actually attempting to import it.

There is no setDataFlavor there is only this, the getDataFlavor, and isDataFlavorSupported in the TransferSupport class, that I have found...


Thanks,

~JO
reply
    Bookmark Topic Watch Topic
  • New Topic