Fetching mouse coordinates

Discussion in 'Java' started by Kevin Pors, Sep 1, 2003.

  1. Kevin Pors

    Kevin Pors Guest

    Is there any way how I can find the coordinates of the mouse on the screen in a static way?
    All posts i've read mention the use of MouseListener and other interfaces which needs motion to determine
    it. I'd like to find the absolute coordinates where the mouse currently is on the screen - NOT relatively of a
    component.
    Kevin Pors, Sep 1, 2003
    #1
    1. Advertising

  2. Kevin Pors

    Kevin Pors Guest

    On Mon, 1 Sep 2003 12:50:14 -0700, "William Brogden" <> wrote:

    >
    >"Kevin Pors" <> wrote in message
    >news:...
    >> Is there any way how I can find the coordinates of the mouse on the screen

    >in a static way?
    >> All posts i've read mention the use of MouseListener and other interfaces

    >which needs motion to determine
    >> it. I'd like to find the absolute coordinates where the mouse currently is

    >on the screen - NOT relatively of a
    >> component.

    >
    >Isn't there a getLocationOnScreen method in the Component class?


    Well it's more complicated than that. The situation is as follows:

    JFrame, grandmother of the application. This frame hold a JToolBar.
    On that toolbar I got my own created component, KButton. I want to create my
    own style of tooltip which is gonna be visible when I hover over the KButton.

    For creating a tooltip thing, I extended JWindow. I need to position that window about 5 pixels down
    and 5 pixels to the right of the cursor.

    I'd like to get the cursor position of the screen without iterating through all the parents. That
    wouldn't be a very clear and vast object oriented manner of programming, IMHO.

    Regards,

    Kevin
    Kevin Pors, Sep 2, 2003
    #2
    1. Advertising

  3. Kevin Pors

    Tim Tyler Guest

    Kevin Pors <> wrote:

    : Is there any way how I can find the coordinates of the mouse on the
    : screen in a static way? All posts i've read mention the use of
    : MouseListener and other interfaces which needs motion to determine
    : it. I'd like to find the absolute coordinates where the mouse currently
    : is on the screen - NOT relatively of a component.

    Java only lets apps know where the mouse is when it is over a Component.

    To read the mouse co-ordinates - and be guaranteed a result - use JNI.
    --
    __________
    |im |yler http://timtyler.org/
    Tim Tyler, Sep 13, 2003
    #3
  4. Kevin Pors

    Tim Tyler Guest

    Kevin Pors <> wrote:
    : On Mon, 1 Sep 2003 12:50:14 -0700, "William Brogden" <> wrote:

    :>Isn't there a getLocationOnScreen method in the Component class?

    : Well it's more complicated than that. The situation is as follows:

    : JFrame, grandmother of the application. This frame hold a JToolBar.
    : On that toolbar I got my own created component, KButton. I want to create my
    : own style of tooltip which is gonna be visible when I hover over the KButton.

    : For creating a tooltip thing, I extended JWindow. I need to position
    : that window about 5 pixels down and 5 pixels to the right of the cursor.

    : I'd like to get the cursor position of the screen without iterating
    : through all the parents. That wouldn't be a very clear and vast object
    : oriented manner of programming, IMHO.

    Surely, the "getLocationOnScreen" method does the iteration for you.

    There is no cause to be concerned about performance here.
    --
    __________
    |im |yler http://timtyler.org/
    Tim Tyler, Sep 13, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Juergen Theis
    Replies:
    0
    Views:
    632
    Juergen Theis
    Feb 21, 2006
  2. Suresh  Kumar
    Replies:
    0
    Views:
    574
    Suresh Kumar
    Jul 3, 2003
  3. Suresh  Kumar
    Replies:
    0
    Views:
    505
    Suresh Kumar
    Jul 4, 2003
  4. Jabba Laci
    Replies:
    3
    Views:
    465
    Jabba Laci
    Aug 17, 2011
  5. Pallavi

    Finding mouse coordinates

    Pallavi, Dec 1, 2003, in forum: Javascript
    Replies:
    2
    Views:
    143
    Richard Cornford
    Dec 2, 2003
Loading...

Share This Page