467,905 Members | 1,863 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,905 developers. It's quick & easy.

mouse coordinates of drop (as in drag and drop)

cte
I have a swing program involving drag and drop - implemented with
javax.swing.TransferHandler etc.

My problem is that I want to determine the mouse coordinates of a drop
onto one of my components and TransferHandler does not seem to have
any means of doing this.

The swing DnD API seems to smoother any mouse listeners that I put up,
so I don't think that approach will work.

Is there some kind of method like getMouseCoordinates () for either a
JComponent or enclosing JFrame etc?

Regards
Chris
Jul 17 '05 #1
  • viewed: 2886
Share:
1 Reply
cte
ct*****@yahoo.com.au (cte) wrote in message news:<c1**************************@posting.google. com>...
I have a swing program involving drag and drop - implemented with
javax.swing.TransferHandler etc.

My problem is that I want to determine the mouse coordinates of a drop
onto one of my components and TransferHandler does not seem to have
any means of doing this.


I don't know if it's bad form to reply to my own post but I've worked
out a semi-solution that does enough. There's a method in
java.awt.Component (which is an ancestor of JComponent): public
DropTarget getDropTarget (). I was able to call this method which
retrieves the Swing implementation (an inner class of
TransferHandler), and add a java.awt.dnd.DropTargetListener to it.

Now for the dodgy bit ;D. The documentation for DropTarget indicates
that only one DropTargetListener may be attached to a DropTarget and
an Exception is thrown if you try to add more than one. However the
inner class of TransferHandler that is a DropTarget does *not* throw
an Exception. Lucky for me, but I'm also uncomfortable relying on a
private implementation detail like this...

Cheers
Chris
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Robin Senior | last post: by
1 post views Thread by Curtis Justus | last post: by
2 posts views Thread by SamSpade | last post: by
14 posts views Thread by Nathan | last post: by
4 posts views Thread by atn2002 | last post: by
2 posts views Thread by bob | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.