is there a way to determine the mouse cursor position apart from
intercepting a mouse event such as drag, i.e., sometimes i want the cursor
position even if no mouse event has taken place
tom arnall
north spit, ca
usa
Loosen up: the tests extend the compiler.

Signature
Posted via a free Usenet account from http://www.teranews.com
John Ersatznom - 18 Dec 2006 20:38 GMT
> is there a way to determine the mouse cursor position apart from
> intercepting a mouse event such as drag, i.e., sometimes i want the cursor
> position even if no mouse event has taken place
What about trapping "mouse move" events? Every time the mouse moves to a
position inside your component it should generate one. If a mouse_pos
value pair is updated by a listener for such an event, it should always
hold the last position the mouse has had inside your component. If you
want the pos when it's outside the component, that may not be possible.
To know when it's left the component, just look for the pos to get near
the edge of the component and then not change for a while.
tom arnall - 18 Dec 2006 21:23 GMT
>> is there a way to determine the mouse cursor position apart from
>> intercepting a mouse event such as drag, i.e., sometimes I want the
[quoted text clipped - 7 lines]
> To know when it's left the component, just look for the pos to get near
> the edge of the component and then not change for a while.
That's the approach I use now: create a mouse move listener and update the
x,y values there for when I need them. But I seems to me that's a lot of
burden on the system, and I'm hoping that java gives more direct access to
the info. It seems to me that java tracks the info anyway, in order to make
the mousemove listener possible, so why not provide access to the info
without requiring a subroutine call e'time the cursor moves a pixel.
tom arnall
north spit, ca
usa

Signature
Posted via a free Usenet account from http://www.teranews.com
Andrew Thompson - 18 Dec 2006 20:47 GMT
> is there a way to determine the mouse cursor position ...
1.5+
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MouseInfo.html#getPointerInfo()>
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/PointerInfo.html#getLocation()>
Andrew T.
tom arnall - 18 Dec 2006 21:28 GMT
>> is there a way to determine the mouse cursor position ...
>
> 1.5+
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MouseInfo.html#getPointerInfo()>
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/PointerInfo.html#getLocation()>
one man's stupid question, another man's prize. thanks very much.

Signature
Posted via a free Usenet account from http://www.teranews.com
tom arnall - 19 Dec 2006 22:22 GMT
>> is there a way to determine the mouse cursor position ...
>
> 1.5+
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MouseInfo.html#getPointerInfo()>
<http://java.sun.com/j2se/1.5.0/docs/api/java/awt/PointerInfo.html#getLocation()>
> Andrew T.
I find with MouseInfo etc that it gives the absolute position of the mouse
cursor. For the position relative to the component on which the cursor is
located, there is Component.getMousePosition() covered at:
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Component.html#getMousePosition()
Thanks for guiding me in the right direction.
tom arnall
north spit, ca
usa

Signature
Posted via a free Usenet account from http://www.teranews.com
Ian Shef - 18 Jan 2007 19:27 GMT
tom arnall <kloro2006@gmail.com> wrote in news:4586dd40$0$15523$88260bb3
@free.teranews.com:
> is there a way to determine the mouse cursor position apart from
> intercepting a mouse event such as drag, i.e., sometimes i want the cursor
> position even if no mouse event has taken place
<snip>
I believe that MouseInfo.getPointerInfo() (in java.awt) will do what you
asked for,
but I think that adding a MouseMotionListener (in java.awt.event) and using
it to keep track is often a better way.

Signature
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *