Skip to main content

Custom Cursor

6 replies [Last post]
cdouglass
Offline
Joined: 2005-08-24
Points: 0

Is there any way to create a custom cursor?

I can get an image loaded, and I can create a java.awt.Cursor. But there doesn't seem to be any way to turn that into a javafx.scene.cursor.

Chas Douglass

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

There is a '[b]fromAWTCursor[/b](c:java.awt.Cursor):Cursor' function in javafx.scene.Cursor class.

[code]
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;

Frame {
stage: Stage {
content: Group{

cursor: Cursor.HAND

content:Circle {
centerX: 100, centerY: 100
radius: 40
fill: Color.BLUE
}
}
}
visible: true
}
[/code]

cdouglass
Offline
Joined: 2005-08-24
Points: 0

That must be in a later update of the SDK than I'm using.

Your example doesn't really seem to jibe with your answer. It just shows using a Cursor constant.

Chas Douglass

cdouglass
Offline
Joined: 2005-08-24
Points: 0

I updated to the latest SDK and the method you mention is there, but it's private, so I can't use it.

Chas Douglass

alexsch
Offline
Joined: 2007-07-12
Points: 0

> I updated to the latest SDK and the method you
> mention is there, but it's private, so I can't use
> it.

Then it is a bug. Could you create an issue on it?
http://openjfx.java.sun.com/jira/secure/CreateIssue!default.jspa

The workaround is to override the fromAWTCursor function to make it public:

[code]
import javafx.application.*;

import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;

public class MyCursor extends Cursor{
public function fromAWTCursor(c:java.awt.Cursor):Cursor {
return super.fromAWTCursor(c);
}
}

Frame {
stage: Stage {
content: Group{

cursor: MyCursor{}.fromAWTCursor(new java.awt.Cursor( java.awt.Cursor.CROSSHAIR_CURSOR))

content:Circle {
centerX: 100, centerY: 100
radius: 40
fill: Color.BLUE
}
}
}
visible: true
}
[/code]

cdouglass
Offline
Joined: 2005-08-24
Points: 0

Issues reported.

When I try your work-around I get:
[code]

/home/chas/nbproj/JFXNav/src/jfxnav/CenterPanel.fx:37: fromAWTCursor(java.awt.Cursor) is not public in javafx.scene.Cursor; cannot be accessed from outside package
[/code]

Chas Douglass

alexsch
Offline
Joined: 2007-07-12
Points: 0

The workaround should work in the NetBeans plugin that uses preview version of JavaFX SDK
http://deadlock.netbeans.org/hudson/job/JavaFX_NB_daily

As I understand, it does not work with JavaFX libraries from trunk brunch of openjfx-compiler