This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Use BufferedImage during Drag and Drop in Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Use BufferedImage during Drag and Drop in Swing" Watch "Use BufferedImage during Drag and Drop in Swing" New topic
Author

Use BufferedImage during Drag and Drop in Swing

Chaz Branham
Ranch Hand

Joined: Apr 04, 2013
Posts: 44

Everyone I am having some problems starting the Drag operation showing an image of the object I want to drag around. I can't seem to get the StartDrag function to work with the parameters I am giving it. If anyone can offer some help I would truly appreciate it.





The function above is where my hard spot is as I can't seem to get it to accept the last two parameters for the Transferable and the DragSourceListener.

Thank you for your help and time,

TheChazm


TheChazm
Chaz Branham
Ranch Hand

Joined: Apr 04, 2013
Posts: 44

I still have not made any headway with this problem. I have looked around the internet and other forums and still can't seem to nail down what am I missing? Any guidance on this would be greatly appreciated and will let me continue to move forward on my project.

Thank you so very much,

Chaz
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Perhaps you could provide a little bit more detail than just

I can't seem to get it to accept the last two parameters


?
Chaz Branham
Ranch Hand

Joined: Apr 04, 2013
Posts: 44

I apologies if I was not clear enough and I'll try to straighten that up.

I am trying to use the StartDrag method to start the drag process. The user would see a semi-transparent image of what they are dragging around is the entire goal.

When I try to use:

startDrag(Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl)

When I hover over what I have provided it in code the Transferable and the DragSourceListener do not have the proper types even though they are implemented in the class. It says it has a type of GangsPanel which is the name of the class that implements both of those methods.

So it has a red X next to that line of code and no matter what I try I can't seem to get it to take the class for those requirements and is where I am stuck. Does that make more sense? I cannot think of any other way of explaining it.

Thanks,

Chaz
Maxim Karvonen
Ranch Hand

Joined: Jun 14, 2013
Posts: 101
    
  10
Hi, Chaz.

It's better to provide compiler message as exactly as they are. Problem is in the third method argument. Look at it. This method requires a point but you are passing an integer.
Chaz Branham
Ranch Hand

Joined: Apr 04, 2013
Posts: 44

Maxim,

Thank you so much for pointing that out for me! It was just the point that was erroring out and I am surprised I didn't catch that.

It does start the StartDrag method now but does not show the image during the drag. Is there something else I am missing?

Thank you so very much!
Maxim Karvonen
Ranch Hand

Joined: Jun 14, 2013
Posts: 101
    
  10
Probably, it shows an image during the drag. You create a fresh new image with alpha support and then use it for the drag "icon". I didn't check, but that image may be transparent from the start. So it is displayed but you can't see any change on the screen. For tests you should take something more-appropriate than a possible-completely-transparent image. Maybe some external image. Or an image filled with some colour (pure red or green, for example). And try to uses a non-transparent image for some time. It much harder to miss a non-transparent image then a transparent one.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Maxim has the right idea there: when you're testing a new feature which you aren't certain about, start with a simple test and then once you have that working, add the complexities one at a time. Starting out with a complex test provides the opportunity for too many things to go wrong all at once.
Chaz Branham
Ranch Hand

Joined: Apr 04, 2013
Posts: 44

Thanks again for the recommendation and your right I should have kept it simple and have been jumping the gun a little bit. I'll give it a go with a non transparent image and see what I get. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use BufferedImage during Drag and Drop in Swing
 
Similar Threads
JScrollPane update
Gui components disappearing
Moving JComponent object based on mouse coordinates
java.lang.ClassCastException but I'm not casting anything
adding graphic objects to JPanel