1 Reply Latest reply: Mar 19, 2011 11:27 PM by darrylburke RSS

    Dragging in Java

      I'm pretty new to these forums (and Java 2D), but I had a quick question on dragging objects in Java.

      This site (http://hypatia.cs.ualberta.ca/reason/index.php?title=Paper:Take_a_WAC_at_writing_in_your_course._(106494)&action=socialnet) was done in flash, but I'm trying to semi-recreate it in Java.

      I made a quick program that plays with dragging and dropping rectangles, but DnD is not really what I'm after. I'd like the drag to be "continuous", basically, the user should be able to see the rectangle and text when dragging it (like the flash app in the above link - try dragging the "center" node). I'm not sure if there are any tutorials, or anything that is like this in Java. I've been looking around, but haven't seen anything that is useful yet. Any information will be much appreciated. Thanks.

      Edited by: 845745 on Mar 19, 2011 11:10 AM

      Edited by: 845745 on Mar 19, 2011 11:10 AM
        • 1. Re: Dragging in Java
          There's no 'ready-made' class for this in the standard JDK, you have to write your own <tt>MouseListener</tt> / <tt>MouseMotionListener</tt> (probably extending <tt>MouseAdapter</tt>) and either move a component in a null layout (or on the glassPane) or use the coordinates obtained from the listeners to perform custom painting.

          You can see an example of the latter approach here:
          Re: making moving eyes in java