• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use BufferedImage during Drag and Drop in Swing

 
Chaz Branham
Ranch Hand
Posts: 53
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chaz Branham
Ranch Hand
Posts: 53
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic