Results 1 to 7 of 7
Thread: Canvas and mouseMoved()
- 07-05-2011, 11:50 PM #1
[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?
Last edited by Zman3359; 07-06-2011 at 12:57 AM.
- 07-06-2011, 12:16 AM #2
Does the component with the listener have the focus?
Is mouseMoved() one of the methods for a MouseListener?
- 07-06-2011, 12:25 AM #3
Yes I call requestFocus(), no it's not. That must be the problem. I fixed it by using addMouseListner() and addMouseMotionListner().
- 07-06-2011, 12:33 AM #4
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.
- 07-06-2011, 12:36 AM #5
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().
- 07-06-2011, 12:48 AM #6
So is the problem solved?
- 07-06-2011, 12:59 AM #7
- By corrax in forum AWT / SwingReplies: 2Last Post: 05-24-2011, 08:35 AM
- By bobbie in forum SWT / JFaceReplies: 0Last Post: 07-05-2009, 12:31 PM
- By tankhardrive in forum New To JavaReplies: 13Last Post: 10-29-2008, 08:08 PM
- By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:06 AM