Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default Mouse coordinates if it goes outside stage

    Hi,
    I m new to javaFX. I wanted to get the pixel co-ordinates of mouse cursor even if the mouse goes outside the stage. Actually I wanted to display all the graphical info to user. Could anyone help and suggest me how can I do this.

    - Kapil

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Mouse coordinates if it goes outside stage

    Take a look at java.awt.MouseInfo.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default Re: Mouse coordinates if it goes outside stage

    Thank you for your reply. but i am not able to get mouse location if it goes outside the container.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Mouse coordinates if it goes outside stage

    Then you didn't use MouseInfo correctly. Post the code you used.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default Re: Mouse coordinates if it goes outside stage

    Here is the code:
    @FXML
    private void mouseMoved(MouseEvent me)
    {
    txt1Text.setText("SceneX:"+me.getSceneX()+"SceneY: "+me.getSceneY());
    txt2Text.setText("ScreenX:"+me.getScreenX()+"Scree nY:"+me.getScreenY());
    txtLabel.setText("X:"+me.getX()+"\n"+"Y:"+me.getY( ));
    mouseInfoUtil();
    }

    private void mouseInfoUtil()
    {

    Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
    String mouseCoordinates = "X: "+ mouseLocation.getX() + " " + "Y: " + mouseLocation.getY();
    lblLocation.setText(mouseCoordinates);

    }

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Mouse coordinates if it goes outside stage

    Please go through BB Code List - Java Programming Forum - Learn Java Programming

    You will need to code a way to call mouseInfoUtil() that doesn't depend on mouseMoved ... maybe using a Timer or Animation.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Mouse coordinates if it goes outside stage

    I don't know JavaFX but I might suggest that instead of asking how to get the coordinates of the mouse when it is outside of a container, you might simply explain what your overall objective is and if it can be done in JavaFX? For example, "I want to write a program to access the various icons on my desktop and do something with them. Is this possible using JavaFX?"

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 6
    Last Post: 11-05-2014, 02:34 AM
  2. Replies: 5
    Last Post: 04-23-2014, 06:49 PM
  3. Replies: 7
    Last Post: 04-10-2010, 07:07 PM
  4. Getting mouse coordinates
    By nishant.4545 in forum Advanced Java
    Replies: 3
    Last Post: 07-20-2009, 11:28 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •