JavaFX Custom Cursors

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()
        x:5 y:5
        width:200 height:200



  1. […] 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 […]

  2. […] posts how to get custom cursors in JavaFX , even when the image is smaller than the required […]

Comments are closed.