Results 1 to 7 of 7
Thread: Canvas and mouseMoved()
- 07-06-2011, 12:50 AM #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 01:57 AM.
- 07-06-2011, 01:16 AM #2
Does the component with the listener have the focus?
Is mouseMoved() one of the methods for a MouseListener?
- 07-06-2011, 01: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, 01: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, 01: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, 01:48 AM #6
So is the problem solved?
- 07-06-2011, 01:59 AM #7
- By corrax in forum AWT / SwingReplies: 2Last Post: 05-24-2011, 09:35 AM
- By bobbie in forum SWT / JFaceReplies: 0Last Post: 07-05-2009, 01:31 PM
- By tankhardrive in forum New To JavaReplies: 13Last Post: 10-29-2008, 09:08 PM
- By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 10:06 AM