I am aware that you can define the cursor through CSS like described in JavaFX custom css cursor or even set it globally like this:
private void setCursor(Scene scene) { Dimension2D dim = ImageCursor.getBestSize(64, 64); URL url; if (dim.getWidth() > 32) { url = getClass().getResource("/icons/64/cursor.png"); } else { url = getClass().getResource("/icons/32/cursor.png"); } try { Image img = new Image(url.openStream()); scene.setCursor(new ImageCursor(img)); } catch (IOException e) { logger.warn("Failed to load cursor icon from {}", url); } }
This however only set's the default cursor globally, while other types of cursor (e.g. caret, processing) remain untouched. Is there a way to supply the JavaFX application with a cursor set that covers all the cases?
Furthermore with the above solution the cursor is tied to the scene, which means, that once it leaves the scene and e.g. hovers over the menu bar, it reverts to the default as set in the OS. Is there a way to define the cursor on the level of the stage or application instead of the scene?
An acceptable answer would also be: cannot be done. Then I do not need to look further.