0

I have a button in my scene where when clicked, the cursor changes to a crosshair and the user can select an X, Y location on the screen with a mouse click, then the cursor changes back. For this, I am using

scene.setCursor(Cursor.CROSSHAIR); //Change cursor to crosshair
scene.setCursor(Cursor.DEFAULT); //Change cursor to default

The problem is, once the mouse is dragged away from the frame, it changes back to default. It only stays as a crosshair when it is within the window. I understand that in Java it is impossible to interact with things outside of the frame, which is why I am using JNativeHook for my mouse listeners in this project. With this, is there a way to change the global cursor?

SedJ601
  • 12,173
  • 3
  • 41
  • 59
Connor S
  • 353
  • 2
  • 12

1 Answers1

2

You can't and you shouldn't change the cursor of the entire screen as the user will get confused about the reason why his mouse is changed but you can do so in two ways

  1. You can make a .bat file that changes the cursor and run this file with administrator privileges from inside the java program you make

    OR
  2. You can make a transparent scene that covers the whole screen so the cursor will always be inside your app which a very bad solution to do and in case your app has a frame it'll not be acceptable but anyway it's a solution
SedJ601
  • 12,173
  • 3
  • 41
  • 59
Ahmed Emad
  • 674
  • 6
  • 19
  • 1
    Solution 2 is how programs like ShareX offer screenshots where you choose the dimensions of the capture. I wouldn't consider it a bad solution as long as any application using this approach offers some way to cancel the screen-covering frame (such as right clicking, in the case of ShareX). – FThompson Aug 22 '18 at 10:19
  • 1
    for his app if it doesn't have a reason to open in full screen it's not a good workaround as an opinion – Ahmed Emad Aug 22 '18 at 10:25
  • The point of changing the cursor was to add a "get mouse position " function to my program. The user clicks a button, then the cursor changes to a crosshair until the next click, after which those coordinates are stored and the cursor changes back. That shouldn't confuse anyone – Connor S Aug 22 '18 at 14:44
  • I think you should have said that before but anyway I think changing the mouse in your window only is working fine with the problem unless you want to change the cursor for the whole OS. Accept the answer if it helps you – Ahmed Emad Aug 23 '18 at 06:22