Article View: borland.public.jbuilder.java.swing
Article #13026getLocationOnScreen
From: mstam
Date: Thu, 08 Oct 1998 00:00
Date: Thu, 08 Oct 1998 00:00
32 lines
1855 bytes
1855 bytes
> > How to get cursor position on screen?
getLocationOnScreen returns the position of a component relative to the
upper left hand corner of the screen.
By using this in combination with the coordinates from a MouseEvent
it is possible to determine the exact position of the mouse
m_SourceComponent is the component providing the mouse events.
Point ptOfRelease = getReleaseCoords( p_MouseReleased );
protected Point getReleaseCoords( MouseEvent p_MouseReleased )
{
Rectangle rectSource = m_SourceComponent.getBounds();
Point ptSource = m_SourceComponent.getLocationOnScreen();
Point ptScreenCoords = new Point();
ptScreenCoords.x = p_MouseReleased.getX() - rectSource.width;
ptScreenCoords.x += rectSource.width + ptSource.x;
ptScreenCoords.y = p_MouseReleased.getY() - rectSource.height;
ptScreenCoords.y += rectSource.height + ptSource.y;
return ptScreenCoords;
}
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
Technical Details
Message-ID:
<6viemj$js3$1@nnrp1.dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6v1hld$2oc9@forums.borland.com> <MPG.107e870dc78d745b98991c@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,8c12370b73b7ec11 X-Google-Attributes: gid111d45,public From: mstam@my-dejanews.com Subject: getLocationOnScreen Date: 1998/10/08 Message-ID: <6viemj$js3$1@nnrp1.dejanews.com> X-Deja-AN: 398977167 References: <6v1hld$2oc9@forums.borland.com> <MPG.107e870dc78d745b98991c@forums.borland.com> X-Http-Proxy: 1.1 x12.dejanews.com:80 (Squid/1.1.22) for client 12.11.151.152 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Oct 08 13:21:30 1998 GMT Newsgroups: borland.public.jbuilder.java.swing X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)