gameCoder95
gameCoder95

Reputation: 359

Javafx 8 how to make mouse cursor invisible?

I am making a 2D shooting game on Javafx 8 and I would like to be able to make the cursor invisible so that I can replace it with crosshairs.

Is there anyway to make the mouse cursor invisible when it is on the scene?

Upvotes: 8

Views: 6645

Answers (2)

Slav
Slav

Reputation: 891

In addition to Vince's response, you can use FXML to make the cursor disappear over a specific control or layout, e.g.:

<?import javafx.scene.Cursor?>
<?import javafx.scene.layout.Pane?>
<Pane ...>
    <cursor>
        <Cursor fx:constant="NONE"/>
    </cursor>
    ...
</Pane>

Upvotes: 0

Vince
Vince

Reputation: 15156

To change your cursor, you'd use the scene.setCursor(String) method.

To change image

Using a reference to your current scene, pass in Cursor.cursor("url") to setCursor:

scene.setCursor(Cursor.cursor("url"));

To remove the cursor

Using a reference to your current scene, pass in Cursor.NONE to setCursor:

scene.setCursor(Cursor.NONE);

You also might be interested in the Cursor.CROSSHAIR value

Upvotes: 13

Related Questions