Results 1 to 7 of 7
  1. #1
    Zman3359's Avatar
    Zman3359 is offline Member
    Join Date
    Jan 2011
    Posts
    42
    Rep Power
    0

    Default [Solved] Canvas and mouseMoved()

    I'm trying to get mouse input for a button class so that I can tell if the mouse is over the button or not. The problem is that I'm not getting any input from mouseMoved(). I'm extending a MouseAdapter and adding it to my Canvas using addMouseListener(). As far as I can tell mouseMoved() isn't even getting called does anyone know why this might be?

    EDIT: Solved
    Last edited by Zman3359; 07-06-2011 at 12:57 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    Does the component with the listener have the focus?
    Is mouseMoved() one of the methods for a MouseListener?

  3. #3
    Zman3359's Avatar
    Zman3359 is offline Member
    Join Date
    Jan 2011
    Posts
    42
    Rep Power
    0

    Default

    Yes I call requestFocus(), no it's not. That must be the problem. I fixed it by using addMouseListner() and addMouseMotionListner().

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    There is more than requesting focus. Is the component focusable?
    There are methods to test that and to set it.
    For debugging add a focus listener and some println to the gained and lost methods to see if/where focus is.

  5. #5
    Zman3359's Avatar
    Zman3359 is offline Member
    Join Date
    Jan 2011
    Posts
    42
    Rep Power
    0

    Default

    Yes, it's focusable I know this because I have a key listener that works fine, and I was getting click input. The problem was that I was using mouseMoved() to get movement and only adding my MouseAdapter using addMouseListener() which doesn't support mouseMoved() so now I use addMouseListener() and addMouseMotionListner() because addMouseMotionListner() supprots mouseMoved().

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    So is the problem solved?

  7. #7
    Zman3359's Avatar
    Zman3359 is offline Member
    Join Date
    Jan 2011
    Posts
    42
    Rep Power
    0

Similar Threads

  1. Need help finding mouseMoved on a JButton
    By corrax in forum AWT / Swing
    Replies: 2
    Last Post: 05-24-2011, 08:35 AM
  2. Replies: 0
    Last Post: 07-05-2009, 12:31 PM
  3. Help with canvas
    By tankhardrive in forum New To Java
    Replies: 13
    Last Post: 10-29-2008, 08:08 PM
  4. Using SWT Canvas
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 09:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •