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));
Type | Property and Description |
---|---|
ReadOnlyDoubleProperty |
hotspotX
The X coordinate of the cursor's hot spot.
|
ReadOnlyDoubleProperty |
hotspotY
The Y coordinate of the cursor's hot spot.
|
ReadOnlyObjectProperty<Image> |
image
The image to display when the cursor is active.
|
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()
Gets the value of the property hotspotX.
|
double |
getHotspotY()
Gets the value of the property hotspotY.
|
Image |
getImage()
Gets the value of the property image.
|
static int |
getMaximumColors()
Returns the maximum number of colors supported in a custom image cursor
palette.
|
ReadOnlyDoubleProperty |
hotspotXProperty()
The X coordinate of the cursor's hot spot.
|
ReadOnlyDoubleProperty |
hotspotYProperty()
The Y coordinate of the cursor's hot spot.
|
ReadOnlyObjectProperty<Image> |
imageProperty()
The image to display when the cursor is active.
|
public final ReadOnlyObjectProperty<Image> imageProperty
Cursor.DEFAULT
will be used.getImage()
public final ReadOnlyDoubleProperty hotspotXProperty
getHotspotX()
public final ReadOnlyDoubleProperty hotspotYProperty
getHotspotY()
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()
Cursor.DEFAULT
will be used.public final ReadOnlyObjectProperty<Image> imageProperty()
Cursor.DEFAULT
will be used.getImage()
public final double getHotspotX()
public final ReadOnlyDoubleProperty hotspotXProperty()
getHotspotX()
public final double getHotspotY()
public final ReadOnlyDoubleProperty hotspotYProperty()
getHotspotY()
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 sequenceSubmit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.