Using MouseMotionListener in order to have a drag and drop effect

Hello,
How is the exact syntax in order for the following code to work even for Drag and Drop effects of the drawn figures.
package tpi;
import java.awt.*;
import java.awt.event.*;
public class Desenare extends Frame{
     private Panel selPanel;
     private Choice sel;
     private Choice fond;
     private Choice lista;
     private MyCanvas canvas;
     public Desenare(String titlu){
          super(titlu);
          selPanel = new Panel(new GridLayout(6,1));
          Label label1 = new Label("Culoare");
          sel = new Choice();
          sel.addItem("Alb");
          sel.addItem("Albastru");
          sel.addItem("Verde");
          sel.addItem("Negru");
          sel.select(0);
          Label label2 = new Label("Figura");
          lista = new Choice();
          lista.addItem("Dreptunghi");
          lista.addItem("Linie");
          lista.addItem("Cerc");
          lista.select(0);
          Label label3 = new Label("Culoare Fond");
          fond = new Choice();
          fond.addItem("Negru");
          fond.addItem("Verde");
          fond.addItem("Albastru");
          fond.addItem("Alb");
          fond.select(0);
          IL itemListener = new IL();
          sel.addItemListener(itemListener);
          fond.addItemListener(itemListener);
          lista.addItemListener(itemListener);
          selPanel.add(label1);
          selPanel.add(sel);
          selPanel.add(label2);
          selPanel.add(lista);
          selPanel.add(label3);
          selPanel.add(fond);
          selPanel.setBackground(Color.LIGHT_GRAY);
          canvas = new MyCanvas();
          add("West",selPanel);
          add("Center",canvas);
          addWindowListener(new WA());
          setSize(400,300);
          setVisible(true);
     class WA extends WindowAdapter{
          public void windowClosing(WindowEvent e){
               System.exit(0);
     class IL implements ItemListener{
          public void itemStateChanged(ItemEvent event){
          canvas.repaint();
     Color genCuloare(String culoare){
          Color color;
          if (culoare.equals("Negru")) color = Color.black;
          else if (culoare.equals("Verde")) color = Color.green;
          else if (culoare.equals("Albastru")) color = Color.blue;
          else if (culoare.equals("Alb")) color = Color.white;
          else color = Color.black;
          return color;
     class MyCanvas extends Canvas{
          public void paint(Graphics g){
          String culoare = sel.getSelectedItem();
          Color color = genCuloare(culoare);
          g.setColor(color);
          color = genCuloare(fond.getSelectedItem());
          setBackground(color);
          Dimension dim = getSize();
          int cx = dim.width/2;
          int cy = dim.height/2;
          String figura = lista.getSelectedItem();
          if (figura.equals("Linie"))
          g.drawLine(cx/2,cy/2,3*cx/2,3*cy/2);
          else if (figura.equals("Dreptunghi"))
          g.fillRect(cx/2,cy/2,cx,cy);
          else if (figura.equals("Cerc"))
          g.fillOval(cx/2,cy/2,cx,cy);
          ML listener = new ML();
          canvas.addMouseMotionListener(listener);
          public class ML implements MouseMotionListener{
               @Override
               public void mouseDragged(MouseEvent arg0) {
                    // TODO Auto-generated method stub
               @Override
               public void mouseMoved(MouseEvent arg0) {
                    // TODO Auto-generated method stub
          public static void main(String []args){
          Desenare d = new Desenare("Desenare 2D");
Where exactly do i have to add the MouseMotionListener , i guess that i should add it to the canvas , and the inherited metod shoul be modified in order to use canvas.repaint() at the location where the draggin effect has ended, or if there is some other way when i press the mouse on the figure and start moving around to getX() and getY() and use the repaint method at those coordinates , wich is a drag and drop effect , i think that it would be MouseMoved , but i`m not sure, and also not sure how to use the Event Listener , where exactly ?
Thanks,
Paul

When you post a code, use code tags for propere formatting. Click CODE icon on the taskbar for generating code tag pair you need.
In order to do dragging the figure on the canvas or panel, you should use advanced Java 2D APIs, including Shape and its descendants. Example shown below might help, but beware, this version does not remember previous drag result for a figure over multiple lista Choice selection. Previous drag result is reset for the next selection of the same figure.
If you want to prevent flickering on the screen while dragging, use javax.swing and its components. If you have to use AWT, draw the figure into an Image or BufferedImage of full panel size and call g2.drawImage() in the paint() method.
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.event.*;
public class Desenare extends Frame{
  private Panel selPanel;
  private Choice sel;
  private Choice fond;
  private Choice lista;
  private MyCanvas canvas;
  Color fcolor, bcolor;
  enum Fig{LINE, RECT, CIRCLE};
  Fig fig;
  int xL0, yL0, xL1, yL1;
  int xR0, yR0, xR1, yR1;
  int xC0, yC0, xC1, yC1;
  int dxL, dyL, dxR, dyR, dxC, dyC;
  Shape shape;
  public Desenare(String titlu){
    super(titlu);
    selPanel = new Panel(new GridLayout(6,1));
    fcolor = bcolor = Color.white;
    dxL = dyL = dxR = dyR = dxC = dyC = 0;
    Label label1 = new Label("Culoare");
    sel = new Choice();
    sel.addItem("Alb");
    sel.addItem("Albastru");
    sel.addItem("Verde");
    sel.addItem("Negru");
    sel.select(0);
    Label label2 = new Label("Figura");
    lista = new Choice();
    lista.addItem("Dreptunghi");
    lista.addItem("Linie");
    lista.addItem("Cerc");
    lista.select(0);
    Label label3 = new Label("Culoare Fond");
    fond = new Choice();
    fond.addItem("Alb");
    fond.addItem("Albastru");
    fond.addItem("Verde");
    fond.addItem("Negru");
    fond.select(0);
    IL itemListener = new IL();
    sel.addItemListener(itemListener);
    fond.addItemListener(itemListener);
    lista.addItemListener(itemListener);
    selPanel.add(label1);
    selPanel.add(sel);
    selPanel.add(label2);
    selPanel.add(lista);
    selPanel.add(label3);
    selPanel.add(fond);
    selPanel.setBackground(Color.LIGHT_GRAY);
    canvas = new MyCanvas();
    add(selPanel, BorderLayout.WEST);
    add(canvas, BorderLayout.CENTER);
    addWindowListener(new WA());
    setSize(400, 300);
    setVisible(true);
  class WA extends WindowAdapter{
    public void windowClosing(WindowEvent e){
      System.exit(0);
  class IL implements ItemListener{
    public void itemStateChanged(ItemEvent event){
      Object o = event.getSource();
      if (o == sel){
        String culoare = sel.getSelectedItem();
        fcolor = genCuloare(culoare);
        canvas.repaint();
      else if (o == fond){
        bcolor = genCuloare(fond.getSelectedItem());
        canvas.setBackground(bcolor);
      else if (o == lista){
        String figura = lista.getSelectedItem();
        if (figura.equals("Linie")){
          fig = Fig.LINE;
        else if (figura.equals("Dreptunghi")){
          fig = Fig.RECT;
        else if (figura.equals("Cerc")){
          fig = Fig.CIRCLE;
        shape = prepareShape(fig);
        canvas.repaint();
  Shape prepareShape(Fig fig){
    Shape shape = null;
    if (fig == Fig.LINE){
      shape = new Line2D.Float(xL0, yL0, xL1, yL1);
    else if (fig == Fig.RECT){
      shape = new Rectangle2D.Float(xR0, yR0, xR1, yR1);
    else if (fig == Fig.CIRCLE){
      shape = new Ellipse2D.Float(xC0, yC0, xC1, yC1);
    return shape;
  Shape prepareShapeDrag(Fig fig){
    Shape shape = null;
    if (fig == Fig.LINE){
      shape = new Line2D.Float(xL0 + dxL, yL0 + dyL, xL1 + dxL, yL1 + dyL);
    else if (fig == Fig.RECT){
      shape = new Rectangle2D.Float(xR0 + dxR, yR0 + dyR, xR1, yR1);
    else if (fig == Fig.CIRCLE){
      shape = new Ellipse2D.Float(xC0 + dxC, yC0 + dyC, xC1, yC1);
    return shape;
  Color genCuloare(String culoare){
    Color color;
    if (culoare.equals("Negru")){
      color = Color.black;
    else if (culoare.equals("Verde")){
      color = Color.green;
    else if (culoare.equals("Albastru")){
      color = Color.blue;
    else if (culoare.equals("Alb")){
      color = Color.white;
    else{
      color = Color.black;
    return color;
  class MyCanvas extends Canvas{
    public MyCanvas(){
      setBackground(Color.white);
      ML ml = new ML();
      addMouseListener(ml);
      addMouseMotionListener(ml);
    public void paint(Graphics g){
      Graphics2D g2 = (Graphics2D)g;
      setCoords();
      g2.setPaint(fcolor);
      if (shape != null){
        g2.draw(shape);
        g2.fill(shape);
    void setCoords(){
      int w = getWidth();
      int h = getHeight();
      xL0 = w / 4;
      yL0 = h / 4;
      xL1 = xL0 * 3;
      yL1 = yL0 * 3;
      xC0 = xR0 = xL0;
      yC0 = yR0 = yL0;
      xC1 = xR1 = w / 2;
      yC1 = yR1 = h / 2;
  public class ML extends MouseInputAdapter{
    Shape s = null;
    Point p0 = null;
    Point p1 = null;
    @Override
    public void mousePressed(MouseEvent e) {
      double dist = 0.0;
      p0 = p1 = e.getPoint();
      if (shape instanceof Line2D){
        dist = ((Line2D)shape).ptSegDist(p0);
        if (dist < 2){
          s = shape;
        else{
          s = null;
      else{
        if (shape.contains(p0)){
          s = shape;
        else{
          s = null;
    @Override
    public void mouseDragged(MouseEvent e) {
      int dx, dy;
      if (s != null){
        p0 = p1;
        p1 = e.getPoint();
        dx = p1.x - p0.x;
        dy = p1.y - p0.y;
        if (s instanceof Line2D){
          dxL += dx;
          dyL += dy;
        else if (s instanceof Rectangle2D){
          dxR += dx;
          dyR += dy;
        else if (s instanceof Ellipse2D){
          dxC += dx;
          dyC += dy;
        shape = Desenare.this.prepareShapeDrag(fig);
        canvas.repaint();
  public static void main(String []args){
    Desenare d = new Desenare("Desenare 2D with Dragging support");
}

Similar Messages

  • I used to be able to copy or drag and drop links from the address window. Now with the update, only the address is copied or dragged not the link. (Says something about not giving site information). I want to be able to drag and drop or copy links.

    Question
    I used to be able to copy or drag and drop links from the address window. Now with the update, only the address is copied or dragged not the link. (Says something about not giving site information). I want to be able to drag and drop or copy links.

    To be more precise, you can setup a JComponent or JPanel on top of your JavaFX nodes that has a TransferHandler that can convert the (AWT/Swing) images dragged to the app to JavaFX image and then insert it into the underlying node.
    As for the file chooser itselft: ListView and the JavaFX composer can allow you to create one quite easily. TreeView can aslso be used to a lesser extend (still a big buggy). For both of these, there are small bugs in the Cell API that may (or may not) prevent from displaying a proper thumbnail in the cells.
    You can also use a regular JFileChooser if you do not mind the dialog box having a different LnF from the rest of your application.

  • How do I move music from iTunes to my iPhone? I have tried dragging and dropping and it doesn't work.

    I have tried dragging and dropping and have also tried creating a file called iPhone.

    Maybe you should read the manual:
    iPhone User Guide (For iOS 5.0 Software)
    If you want to drag and drop, then check the Manually manage music box. Otherwise sync your content.

  • If an iPod is in "use as hard disk" mode, could I drag and drop songs to it

    After countless attempts to sync my iTunes into this iPod I just obtained, with iTunes, Finder, sometimes both programs hanging and freezing up, since I pick "use iPod as hard disk" as an option, couldn't I just drag and drop my iTunes tracks into the iPod via just a pair of Finder windows? I mean if it can work like a USB drive, I think it wouldn't be impossible to do the same with my songs, since they are just files as well, since I am having such a horrible ordeal syncing this iPod. I am on the verge of my 6th Restore in almost as many days and at best I could load songs into it one by one, but sometimes it would even balk for the most curious reasons such as:
    song running over 5 1/2 minutes in length
    song consisting of mp3 I d/l-ed elsewhere independent of iTunes Store
    song purchased from iTunes a very long time ago
    the 4th or 6th song in a row being synced, no matter the type
    I have little idea why this iMac is giving me so much guff, as my sister has the same model that works without complaint for her.

    Curses, foiled again! Maybe you additionally have an idea why my 4th gen 20 GB iPod seems to make Finder, iTunes, and occasionally Disk Utility hang and stop responding when all I am trying to do is attempt to make the iPod work as designed ie: accept my iTunes songs, keep them and have them available for playback. It is fully charged, yet most of the time it chokes when I am trying to Restore it, so every time I do manage to restore it, it takes about 4 or 5 incremental attempts of completing Restore until I get it going again. Then I am only able to get it running by manually loading the songs one track at a time until I get up to about 30 or so and it unravels upon my attempts to put all of them on, even adding them manually one song at a time.

  • Problem using text boxes as the "image" to drag and drop over audio file

    I have been adding audio files to my page in iWeb (previous version, not '08), but I am having a problem giving them titles.
    When you first drag a file from iTunes into iWeb, it provides a space for you to drag and drop a picture. The online iWeb guide also says that you can drag a text box there instead of a picture.
    I created a text box with the text I would like to drop over the controller. However, it is no longer allowing me to drop the text box there. I used to be able to do this, and I don't know what I'm doing differently now. Any suggestions?
    Thanks!
    -- Will

    foobar2000 with the ipod plugin will allow you to drag/drop FLAC files and when it syncs the ipod, it converts the FLAC files on the fly. MUCH better than dealing with the crappy iTunes interface and having to pre-convert the files. I absolutely loathe iTunes and it just gets worse and worse!

  • How do I copy music downloaded from Cd or Itunes to differnt folders? Have tried drag and drop

    How do I copy music downloaded from Cd or Itunes to differnt folders? Have tried drag and drop

    How to use your iPod to move your music to a new computer

  • Organizing podcasts that have been dragged and dropped

    I normally get my podcasts thru iTunes, so they are nice and organized in the Podcast section of iTunes. But I've just started getting some non-iTunes podcasts and can't figure out best way to organize.
    Most of the podcasts are episodes from a series or program, but when drag and dropping them into iTunes, they show up as individual podcasts. Is there a way to create a show that nests the episodes, as iTunes does when downloading from the iTunes Store? For instance I have NPR Fresh Air and within that menu there are all the episodes, but they are nested under Fresh Air. Is there a way to create a program that I can then put episodes into?
    If I already have a a program listed in iTunes (again, NPR Fresh Air) with episodes nested under that listing, is there a way to Add episodes to that listing that were NOT downloaded thru iTunes (I have some episodes my wife downloaded directly thru the NPR website).
    I'm on iTunes 9.
    Many thanks!!

    Hi,
    Please send several test emails with attachments on OWA, check if this issue will occur.
    If the issue is on client only, we can start Outlook in Safe Mode to test, this can eliminate the influence by 3rd-party add-ins:
    Press Win + R, type "outlook.exe /safe" in the blank box, press Enter.
    In Outlook Safe Mode, send several test emails with attachments to see if the problem will ever occur. If no, we may suspect the issue was caused by some add-ins, go to FILE -> Options -> Add-Ins to disable the suspicious add-ins to verify which one
    caused the problem.
    We can also test with a new profile to setup the account, a new profile will be a new environment for the account, we can check if the problem will occur with the new profile and you don't need to remove the old profile.
    To create a new profile, go to Control Panel -> Mail -> Show Profiles -> Add.
    Regards,
    Melon Chen
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Outlook 2010 with 365 stripping attachments off of email that have been drag and dropped

    In my office we just switched to 365 and since this I've noticed that roughly 1/3 to 1/2 of my email with drag and drop attachments are having those attachments stripped off.
    Several times a day I send an email that has 6 attachments, mix of excel and pdf, and the excel called 'Checklist' I attach by drag and drop often get stripped off the instant I hit the Send button.  
    I will literally be looking at it, as one of 6 files, hit Send, and in my sent box there are only 5 files, the Checklist is gone!  It's random; about 1/3 to 1/2 of them do this.  Others make it through.
    Please let me know if there is a fix to this?  I'm having to resend attachments about 6 times a day now! 

    Hi,
    Please send several test emails with attachments on OWA, check if this issue will occur.
    If the issue is on client only, we can start Outlook in Safe Mode to test, this can eliminate the influence by 3rd-party add-ins:
    Press Win + R, type "outlook.exe /safe" in the blank box, press Enter.
    In Outlook Safe Mode, send several test emails with attachments to see if the problem will ever occur. If no, we may suspect the issue was caused by some add-ins, go to FILE -> Options -> Add-Ins to disable the suspicious add-ins to verify which one
    caused the problem.
    We can also test with a new profile to setup the account, a new profile will be a new environment for the account, we can check if the problem will occur with the new profile and you don't need to remove the old profile.
    To create a new profile, go to Control Panel -> Mail -> Show Profiles -> Add.
    Regards,
    Melon Chen
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • 90% of pictures disappeared after new program. Time machine folders mostly empty. Downloaded my Carbonite file. Can I restore directly from this file or do I have to drag and drop 20,000 pix?

    90% of pictures disappeared after adding Maverick. My Time Machine folders were in the right order but mostly empty so useless for restore. Repair and rebuild attempts were not effective. Downloaded my Carbonite file which is now sitting on my desktop. Is there any way to use the restore command to rebuild my portfolio or do I have to drag & drop approx 20,000 pictures? Can album groupings and faces be retained?

    Do you still have the original library that was present at the time you upgraded to Mavericks?  If so apply the two fixes below in order as needed:
    Fix #1
    1 - launch iPhoto with the Command+Option keys held down and rebuild the library.
    2 - run Option #4 to rebuild the database.
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    1 - download iPhoto Library Manager and launch.
    2 - click on the Add Library button and select the library you want to add in the selection window..
    3 - Now that the library is listed in the left hand pane of iPLM, click on your library and go to the Library ➙ Rebuild Library menu option.
    4 - In the next  window name the new library and select the location you want it to be placed.
    5 - Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments but not books, calendars or slideshows. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    Happy Holidays

  • Video Blink drag and drop effect in Premier Pro

    Hey there!
    Recently made the switch from FCP7 to PP CC and I'm wondering if anyone has encountered frustrations with not being able to find an effect in PP to mimc the Blink one in F
    Nothing complicated, just trying to layer one video over the other and have the top one flash from 0-100% opacity (or on or off) repeatedly. Preferably with some sort of control of the rate that it does this (in FCP there is a "Frames off (#) versus Frames on (#)")
    Everywhere I look people seem to keep telling me "Just keyframe the opacity at 0% frame over the desired amount and key frame at 100%, then repeat until the clip is do
    Not only is it crazy labour intensive just to pull off a basic effect that way but theres no way to change your on/off rate short of redoing the entire process.
    I've loved making the switch to PP so far but this is an effect that I get a serious amount of use out of and it's driving me insane.
    Thanks for any help/advice!t
    Ma

    Hi Mat,
    Check out the Strobe Light Effect under Stylize. It will do what you want. Has even more parameters than FCP did.
    Thanks,
    Kevin

  • Do I need to have data before performing Drag and Drop????

    I have gotten drag and drop working with Swing in JDK 1.4b2 using "URL-based" files instead of operating system native files. The way this was accomplished by creating a wrapper class that sub-classed File and would download the contents of the URL to a temporary file and then initiate a normal drag and drop operation using the normal java file mechanisms. However, when you have a large file, the operation can take too long since I am fronting all of the effort at the start of the drag. I would like to be able to delay the need to produce the bytes/files to give to the operating system until after there has been a successful drop, at which point I can do the heavy lifting and raise a dialog telling them that the action is commencing. As best as I can tell, you must have all of the data BEFORE any operation (which could be a potential design flaw!!)
    So, is there a way to get a hook that there has been a successful drop to a vm-external drop target before the VM gives the data over? Even if I create my own data flavor (which isn't well documented outside of Text types) won't I still run into the same problems? Am I just overlooking something simple?
    Thanks for your help.

    Hello
    I've had the same problem, but take a look at: http://foxtrot.sourceforge.net/
    You can use their API to start the long consuming time job (reading files from the network) and also to paint a progress bar, showing the progress in the Event Dispatch Thread.
    This is how I've solved my problem:
    I've passed a MyTransferable object to the startDrag method of the DragGestureEvent event.
    In the getTransferData method of MyTransferable object (that implements Transferable interface) I've used the Worker.post method of their API which reads the file from the network and updates a progress bar.
    The API lets the Event Dispatch Thread enter but not return from the listener method (getTransferData in my case), instead rerouting the Event Dispatch Thread to continue dequeuing events from the Event Queue and processing them (repaint the progress bar). Once the worker thread has finished, the Event Dispatch Thread is rerouted again, returning from the listener method.

  • CP 6.1 Drag and drop interaction - can it be edited/viewed/published by someone using CP6?

    Hi all,
    I am reasonably new to Captivate. I have a subscription to Captivate 6.1 which now has the new Drag and Drop wizard.
    My question is:
    If I include a drag and drop interaction in my .cptx file, save it and then give the file to person X to review/edit, but they DO NOT have the drag and drop feature in their version of Captivate (they have Captivate 6), can they:
    a: view it?
    b. edit it?
    c. even if they can't view or edit, could they still publish the file from their end and the drag and drop will work fine and not be affected?
    Thanks!
    Veronica

    Hi Veronica,
    Although there is now compatibility between 6.01 and 6.1, which means that your colleagues will be able to open your file, I don't believe they'll be able to edit the interaction at all. And of course publishing will not be possible either. Because I have still 6.01 installed on my laptop and 6.1 on my desktop PC, I can try it out if you want to be totally sure, but for the moment I'm in college and only have laptop with me.
    Lilybiri

  • Problem with Calendar and drag and drop a name to a Time spot with palm desktop. Full name does not appear only last name.

    Im having a problem with the palm desktop. When in “Contacts” and I list (LastName,First name) and then I move to the Calendar and drag and drop a name to a Time spot Only the LAST name of the Person appears. How can I fix this so that I can see there full name ?
    Also when If list (Company,Last Name) then go to calendar Some of my contacts are out of order but if I drag and drop them into the calendar day the full name appears. Is there any why of fixing this ? Or having it work properly ?
    Im running  XP pro
    Palm Desktop Version 4.1.4
    Post relates to: Treo 680 (Rogers)
    Message Edited by corrado on 07-21-2008 08:55 AM

    Any Idea how to fix the problem that I am getting when using the (Company,Last Name) and the contacts being out of order in the calander ? I have some last names starting with A then it goes to D then a B then a stack more A and none of then have a Company field filled out in them in them...
    Thanks for looking into that for me but it seems really stange to offer the option but not put in the first name in the calander when you drage the name over. I hope this is fixed in the future. Can anyony sugest another desktop platform I can use if I cant fix my problem with the   (Company,Last Name) problem?
    Post relates to: Treo 680 (Rogers)

  • Is there a way to disable drag-and-drop on the pages panel?

    Hi, I'm using Indesign CS3 on Windows XP.  My computer is a laptop and the problem I'm having is that when I have the pages panel open, I have sometimes drag-and-dropped pages of a document into a new order without meaning to (the laptop touch pad seems made for these butterfingers-type moves).  The documents that I'm laying out are several hundred pages long, so sometimes I don't notice that I've screwed a few pages up until much later.  If there is any way to just turn this feature off, that would be great.  Due to the arrangement in which I usually work best (on a sofa), I would prefer not to have to attach an actual mouse to the laptop. Thank you for any help.

    Not that I know of.

  • Autoscrolling in a DropTarget (Drag and Drop)

    I have implemented Drag and Drop using DropTargets and a DragSource And DragGestureListener.
    The DropTarget I have is a customized JComponent. How can I make the DropTarget autoscroll for Drag and Drop events??

    Have you tried adding a MouseMotionListener to the target component and checking to see if the mouse coordinates are near the edge of the viewable area?

Maybe you are looking for