Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drag and Drop/Transfer handling help

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 21298
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 21298
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic