public class ImageCursor extends Cursor
Cursor.DEFAULT will be used in place of the
specified ImageCursor.
Example:
import javafx.scene.*;
import javafx.scene.image.*;
Image image = new Image("mycursor.png");
Scene scene = new Scene(400, 300);
scene.setCursor(new ImageCursor(image,
image.getWidth() / 2,
image.getHeight() /2));
| Constructor and Description |
|---|
ImageCursor()
Constructs a new empty
ImageCursor which will look as
Cursor.DEFAULT. |
ImageCursor(Image image)
Constructs an
ImageCursor from the specified image. |
ImageCursor(Image image,
double hotspotX,
double hotspotY)
Constructs an
ImageCursor from the specified image and hotspot
coordinates. |
| Modifier and Type | Method and Description |
|---|---|
static ImageCursor |
chooseBestCursor(Image[] images,
double hotspotX,
double hotspotY)
Creates a custom image cursor from one of the specified images.
|
static Dimension2D |
getBestSize(double preferredWidth,
double preferredHeight)
Gets the supported cursor size that is closest to the specified preferred
size.
|
double |
getHotspotX() |
double |
getHotspotY() |
Image |
getImage() |
static int |
getMaximumColors()
Returns the maximum number of colors supported in a custom image cursor
palette.
|
ReadOnlyDoubleProperty |
hotspotXProperty() |
ReadOnlyDoubleProperty |
hotspotYProperty() |
ReadOnlyObjectProperty<Image> |
imageProperty() |
public ImageCursor()
ImageCursor which will look as
Cursor.DEFAULT.public ImageCursor(Image image)
ImageCursor from the specified image. The cursor's
hot spot will default to the upper left corner.image - the imagepublic ImageCursor(Image image, double hotspotX, double hotspotY)
ImageCursor from the specified image and hotspot
coordinates.image - the imagehotspotX - the X coordinate of the cursor's hot spothotspotY - the Y coordinate of the cursor's hot spotpublic final Image getImage()
public final ReadOnlyObjectProperty<Image> imageProperty()
public final double getHotspotX()
public final ReadOnlyDoubleProperty hotspotXProperty()
public final double getHotspotY()
public final ReadOnlyDoubleProperty hotspotYProperty()
public static Dimension2D getBestSize(double preferredWidth, double preferredHeight)
Note: if an image is used whose dimensions don't match a supported size (as returned by this method), the implementation will resize the image to a supported size. This may result in a loss of quality.
Note: These values can vary between operating systems, graphics cards and screen resolution, but at the time of this writing, a sample Windows Vista machine returned 32x32 for all requested sizes, while sample Mac and Linux machines returned the requested size up to a maximum of 64x64. Applications should provide a 32x32 cursor, which will work well on all platforms, and may optionally wish to provide a 64x64 cursor for those platforms on which it is supported.
preferredWidth - the preferred width of the cursorpreferredHeight - the preferred height of the cursorpublic static int getMaximumColors()
Note: if an image is used which has more colors in its palette than the supported maximum, the implementation will attempt to flatten the palette to the maximum. This may result in a loss of quality.
Note: These values can vary between operating systems, graphics cards and screen resolution, but at the time of this writing, a sample Windows Vista machine returned 256, a sample Mac machine returned Integer.MAX_VALUE, indicating support for full color cursors, and a sample Linux machine returned 2. Applications may want to target these three color depths for an optimal cursor on each platform.
public static ImageCursor chooseBestCursor(Image[] images, double hotspotX, double hotspotY)
On platforms that don't support custom cursors, Cursor.DEFAULT will
be used in place of the returned ImageCursor.
images - a sequence of images from which to choose, in order of preferencehotspotX - the X coordinate of the hotspot within the first image
in the images sequencehotspotY - the Y coordinate of the hotspot within the first image
in the images sequenceCopyright © 2025. All rights reserved.