I'm using the property "-fx-cursor: <url>" but its not changing the icon of the mouse pointer.
The only way that I got a ImageCursor was using "scene.setCursor(new ImageCursor(...));", but the cursor is changed by any node that has a "-fx-cursor"
UPDATE: Complete TestCase
TestCursor.java
import java.lang.reflect.Method;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Cursor;
import javafx.scene.ImageCursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import com.sun.javafx.cursor.CursorFrame;
import com.sun.javafx.cursor.CursorType;
@SuppressWarnings("restriction")
public class TestCursor extends Application {
private static final String url = "http://docs.oracle.com/cd/E27300_01/E27309/html/images/oracle_logo.png";
private static CursorType expectedType;
private static CursorType getCursorType(Cursor cursor) {
try {
Method method = Cursor.class.getDeclaredMethod("getCurrentFrame");
method.setAccessible(true);
CursorFrame frame = (CursorFrame) method.invoke(cursor);
return frame.getCursorType();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String... args) {
ImageCursor imageCursor = new ImageCursor(new Image(url));
expectedType = getCursorType(imageCursor);
Application.launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Pane pane = new Pane(new Button("Button"));
pane.setStyle(String.format("-fx-cursor: \"%s\"", url));
stage.setOnShown(event -> {
Cursor cursor = pane.getCursor();
CursorType cursorType = getCursorType((ImageCursor) cursor);
if (expectedType.equals(cursorType)) {
System.out.println("It works");
} else {
System.out.println("Must be equals");
}
Platform.exit();
});
stage.setScene(new Scene(pane));
stage.show();
}
}
The only way that I got a ImageCursor was using "scene.setCursor(new ImageCursor(...));", but the cursor is changed by any node that has a "-fx-cursor"
UPDATE: Complete TestCase
TestCursor.java
import java.lang.reflect.Method;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Cursor;
import javafx.scene.ImageCursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import com.sun.javafx.cursor.CursorFrame;
import com.sun.javafx.cursor.CursorType;
@SuppressWarnings("restriction")
public class TestCursor extends Application {
private static final String url = "http://docs.oracle.com/cd/E27300_01/E27309/html/images/oracle_logo.png";
private static CursorType expectedType;
private static CursorType getCursorType(Cursor cursor) {
try {
Method method = Cursor.class.getDeclaredMethod("getCurrentFrame");
method.setAccessible(true);
CursorFrame frame = (CursorFrame) method.invoke(cursor);
return frame.getCursorType();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String... args) {
ImageCursor imageCursor = new ImageCursor(new Image(url));
expectedType = getCursorType(imageCursor);
Application.launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Pane pane = new Pane(new Button("Button"));
pane.setStyle(String.format("-fx-cursor: \"%s\"", url));
stage.setOnShown(event -> {
Cursor cursor = pane.getCursor();
CursorType cursorType = getCursorType((ImageCursor) cursor);
if (expectedType.equals(cursorType)) {
System.out.println("It works");
} else {
System.out.println("Must be equals");
}
Platform.exit();
});
stage.setScene(new Scene(pane));
stage.show();
}
}