Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2005

Tip: Looking for answers? Try searching our database.

Mouse position after DND (using TransferHandler)

Thread view: 
Frank Dannemann - 04 Sep 2003 15:35 GMT
Hello,

I want get the mouse position after a DND operation on the target
component where the mouse was released for the drop.

My current setup is a JTree which I drag objects from, and a JPanel
that I drop objects to. I have implemented my own Transferable, and a
TransferHandler for both the JTree and the JPanel. Everything works
fine with the drag and drop, but I can't figure out where the drop
operation took place. The importData method gives me access to the
Transferable and the JComponent, but not the MouseEvent. I tried
setting up a MouseAdapter and watching for a mouseReleased on the
JPanel, but that never seemed to be triggered during a drop.

How do I determine the drop location, or even get the mouse event that
ended the drag?

Thanks in advance for any help.
Regards.

Frank
Shannon Hickey - Swing Team - 06 Sep 2003 20:21 GMT
Hi Frank,

> Hello,
>
[quoted text clipped - 17 lines]
>
> Frank

Right now, the way to figure out where the drop took place is to query
the component's selection. As the drag is happening over your tree,
Swing should be updating the selection to show where the drop will
occur. You can query the tree's selection to see which node was
selected when the drop occurred.

In the future, we'd like to provide a better way to indicate/query the
drop location. This is being tracked as bug number 4468566
(http://developer.java.sun.com/developer/bugParade/bugs/4468566.html).

Thanks!
Shannon
--
Shannon Hickey
shannon1@swingteam.com
Swing Team  http://TheSwingConnection.com  http://TheJavaTutorial.com
Java Software,  a division of Sun Microsystems, Inc.
Frank Dannemann - 08 Sep 2003 12:38 GMT
Hi Shannon,

> Right now, the way to figure out where the drop took place is to query
> the component's selection. As the drag is happening over your tree,
> Swing should be updating the selection to show where the drop will
> occur. You can query the tree's selection to see which node was
> selected when the drop occurred.

Yes, this way your suggested solution seems to work. The problem in my
special case occurs in the other case (if the user wants to drop
something inside the JPanel), because there's nothing really selected
before the drop operation takes place: the user starts the DnD with the
selection of an icon residing in the JTree. Afterwards the selected Icon
has to be dragged to a JPanel with a JGraph component into it (cf. to
http://jgraph.sourceforge.net/ ). After the drop a new cell will be
created in the graph and the data will be transfered via the two
assigned TransferHandlers. The problem is now to get the correct posion
into the graph where the new cell has bo be displayed.

> In the future, we'd like to provide a better way to indicate/query the
> drop location. This is being tracked as bug number 4468566
> (http://developer.java.sun.com/developer/bugParade/bugs/4468566.html).

Very good, thank you. But is there really no workaround? At the moment
I've absolutely no idea how to solve this problem, because I don't want
to step back to the "old" DnD mechanism in java versions prior to 1.4.

Thanks again for your help.

-Frank

Signature

Frank Dannemann                         Phone :    +49 (0)531/295-2782
German Aerospace Center (DLR)           Fax   :    +49 (0)531/295-2767
Simulation and Software Technology      E-Mail: Frank.Dannemann@DLR.de

Shannon Hickey - Swing Team - 11 Sep 2003 03:58 GMT
Hi Frank,

> Hi Shannon,
>
[quoted text clipped - 26 lines]
>
> -Frank

There's definitely a way! I just had to do a little investigation to
figure out what it is :)

After you set the TransferHandler on your JPanel, add the following
lines of code:

// Do this AFTER setting the TransferHandler. The installation of a
// TransferHandler causes a NEW DropTarget to be installed
panel.getDropTarget().addDropTargetListener(new DropTargetListener() {
   public void dragOver(DropTargetDragEvent e) {
       // This point contains the point in your component where
       // the cursor currently is. You can save the location for
       // use in importData().
       Point p = e.getLocation();
   }

   public void dragEnter(DropTargetDragEvent e) {}
   public void dragExit(DropTargetEvent e) {}
   public void drop(DropTargetDropEvent e) {}
   public void dropActionChanged(DropTargetDragEvent e) {}
});

Please let me know how that works.

Regards,
Shannon
--
Shannon Hickey
shannon1@swingteam.com
Swing Team  http://TheSwingConnection.com  http://TheJavaTutorial.com
Java Software,  a division of Sun Microsystems, Inc.
Frank Dannemann - 11 Sep 2003 10:20 GMT
Hello Shannon,

> There's definitely a way! I just had to do a little investigation to
> figure out what it is :)

Thanks a lot for the effort you put into this. I appreciate your
expert help very much! Your answer would definitely be worth the duke
dollars I assigned to this item in the "Project Swing" forum on
java.sun.com :-)

> Please let me know how that works.

It works perfectly! There's nothing to complain about ;-) Perhaps you
should add this solution in the workaround section of the bug you
opened (bug number 4468566).

Regards,

Frank

Signature

Frank Dannemann                         Phone :    +49 (0)531/295-2782
German Aerospace Center (DLR)           Fax   :    +49 (0)531/295-2767
Simulation and Software Technology      E-Mail: Frank.Dannemann@DLR.de

Sudeep - 29 Aug 2005 10:06 GMT
Hello Franc,

I also need to drag from a JTree to a JGraph. But I'm wondering how to start
that. So it would be kind if you'd mail me a sample example at
sks_sudeep@yahoo.com. Your help would mean a lot to me.

Thanks in advance !

- Sudeep

>Hello Shannon,
>
[quoted text clipped - 15 lines]
>
>Frank


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.