This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Ghost image with drag and drop

 
Jonathan Moore
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm implementing drag and drop into my application and am trying to display a ghosted image of the dragged component during the drag. There is an example of this in the Swing Hacks book - it involves creating a glass pane and painting the component on it with the opacity set to 0.5. Not a problem.

However the example given only shows the movement of the source component and doesn't actually implement drag and drop. You need to add a MouseMotionListener to the source component to do the animation, but I've found that once you've called setTransferHandler on a Component you can't then add a MouseMotionListener (or you can but the events don't get called). Has anyone attempted this before, and is it possible to set the transfer handler AND a MouseMotionListener on the same component?

Thanks for any help,
Jon
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the DragnGhostDemo code example and tried it.
Your question raises many possibilities.
The DragnGhostDemo drags images of JLabels, JButtons and a JTable. Java drag_n_drop is
not designed to drag buttons and labels and will drag data from tables. So implementing
drag_n_drop on some of these components using TransferHandlers doesn't seem feasible.
It is easy enough to drag and drop these components without using TransferHandlers. The
way the DragnGhostDemo app is put together it appears that it would be easy to modify it
to do this. You would have to work out the drop target part, ie, how to deal with the
dropped component.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!