wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes How to set a dataflavor to a component? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to set a dataflavor to a component?" Watch "How to set a dataflavor to a component?" New topic
Author

How to set a dataflavor to a component?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 354

Okay so I had a Q on here before having to do with Drag and Drop; however didn't get what I was looking 4... I am creating a custom flavor. I see that you can do isDataFlavorSupported(DataFlavor df) with the Transfer handler, but no setting it? I also checked out the component class to see if it cold set it. It can do other things, no Data flavor tho... The Oracle Trail doesn't give me anything that I noticed. Can anyone link me to where I can locate this? Maybe I'm over thinking it, wold creating the df be enough(don't think so), or how do I Support it?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18167
    
    8

What I did was this: I have a class which extends TransferHandler. And it overrides the method public Transferable createTransferable(JComponent).

Inside this method I construct and return a DataHandler object (it's a Transferable) and that's where I set the DataFlavor for the component. The code I use for the DataFlavor is like this:



Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 354

Paul Clapham wrote:What I did was this: I have a class which extends TransferHandler. And it overrides the method public Transferable createTransferable(JComponent).

Inside this method I construct and return a DataHandler object (it's a Transferable) and that's where I set the DataFlavor for the component. The code I use for the DataFlavor is like this:





Thanks Paul, I actually found some code that explains it like how you said

http://docstore.mik.ua/orelly/java-ent/jfc/ch06_01.htm



I am also starting to notice a lot of code is taking a super class and editing it to your need :)

Also works hmm..? I thoght I wold have to do something liek DataFlavor d = new DataFlavor(String mimeType, String humanPresentableName)




I've seen it where it wants sometimes it's I've noticed...


Wold it matter if I extended Transferable or Transfer Handler?



Also sir, what is the big difference Between Local JVMObject and a nonlocal? I was reading up on it and it seemed Local had to do with the one class only, and nonlocal seemed to work over the web or 4 multiple projects and such
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18167
    
    8

Jay Orsaw wrote:I am also starting to notice a lot of code is taking a super class and editing it to your need :)


Yep, especially in the Swing world where often your goal is to take an existing component and modify it to work your way.

Also works hmm..? I thoght I wold have to do something liek DataFlavor d = new DataFlavor(String mimeType, String humanPresentableName)


What I posted is based on what I ended up with, four or five years ago, after a couple of weeks working with the tutorial and messing about until I had working code. So it possibly isn't exactly what a professional would come up with. Anyway I suspect that if you're only dragging and dropping within your own application, the data flavour names might not matter as much as if you were planning to drag from (or worse, drop onto) another application. So carry on messing about and eventually you'll find what works and what doesn't.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 354

Paul Clapham wrote:
Jay Orsaw wrote:I am also starting to notice a lot of code is taking a super class and editing it to your need :)


Yep, especially in the Swing world where often your goal is to take an existing component and modify it to work your way.

Also works hmm..? I thoght I wold have to do something liek DataFlavor d = new DataFlavor(String mimeType, String humanPresentableName)


What I posted is based on what I ended up with, four or five years ago, after a couple of weeks working with the tutorial and messing about until I had working code. So it possibly isn't exactly what a professional would come up with. Anyway I suspect that if you're only dragging and dropping within your own application, the data flavour names might not matter as much as if you were planning to drag from (or worse, drop onto) another application. So carry on messing about and eventually you'll find what works and what doesn't.


Yeah I was trying to see how to support my own, and it seems I have to do like the tut shows... I'll do it buntil it works... By the way thanks again 4 helping me with the rectangle issue I realized it had to do with some stuff in the face class and once I changed it and draw extended jpanel it worked.... Now I'm working on selecting and moving multiple faces :).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set a dataflavor to a component?
 
Similar Threads
Dnd not serializable
How to issue command in Java program
implement drag drop.
Cut/copying and pasting custom object types
Drag and Drop/Transfer handling help