JavaFX Custom Cursors
Monday, 30 March 2009
Setting custom cursors with JavaFx is relatively straightforward, but for one little catch. Your image has to be 32×32. If you want a 16×16 icon, simply leave the rest of the image transparent.
import java.awt.Toolkit;
import javafx.scene.Cursor;
import javafx.scene.image.Image;
public class ColorChooser extends Cursor
{
public override function impl_getAWTCursor(): java.awt.Cursor {
def url = "{__DIR__}eyedropper.png";
var toolkit = Toolkit.getDefaultToolkit();
var image = Image{width:32 height:32 url:url}.bufferedImage;
var hotspot = new java.awt.Point(0,15);
var cursor = toolkit.createCustomCursor(image, hotspot, "colorpicker");
return cursor;
}
}
public def ColorChooserCursor=ColorChooser{};
public function run()
{
javafx.scene.shape.Rectangle
{
x:5 y:5
width:200 height:200
cursor:ColorChooserCursor
}
}
Tags: javafx
You should follow me on twitter here
No. 1 — May 12th, 2009 at 1:20 am
[...] to say, when I read the Chui’s Counterpoint blog post entitled JavaFX Custom Cursors, I had flashbacks to the Emily Litella SNL appearances (my favorite one being where she wondered [...]
No. 2 — May 18th, 2009 at 7:10 am
[...] posts how to get custom cursors in JavaFX , even when the image is smaller than the required [...]