• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ghost image with drag and drop

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Water proof donuts! Eat them while reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic