Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

determine the mouse cursor position without mouse event

Thread view: 
tom arnall - 18 Dec 2006 19:24 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

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    *



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.