Top Description Fields Constructors Methods
org.eclipse.swt.graphics

public final Class Cursor

extends Resource
Class Inheritance
Imports
org.eclipse.swt.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*

Instances of this class manage operating system resources that specify the appearance of the on-screen pointer. To create a cursor you specify the device and either a simple cursor style describing one of the standard operating system provided cursors or the image and mask data for the desired appearance.

Application code must explicitly invoke the Cursor.dispose() method to release the operating system resources managed by each instance when those instances are no longer required.

Styles:
CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP, CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE, CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE, CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND

Note

Only one of the above styles may be specified.

See Also
Cursor snippets, Sample code and further information

Field Summary

Modifier and TypeField and Description
public long
handle

the handle to the OS cursor resource (Warning: This field is platform dependent)

Important Note

This field is not part of the SWT public API.

Inherited from org.eclipse.swt.graphics.Resource:
device

Constructor Summary

AccessConstructor and Description
pack-priv
Cursor(Device device)

public
Cursor(Device
the device on which to allocate the cursor
device
,
int
the style of cursor to allocate
style
)

Constructs a new cursor given a device and a style constant describing the desired cursor appearance.

public
Cursor(Device
the device on which to allocate the cursor
device
,
ImageData
the color data for the cursor
source
,
ImageData
the mask data for the cursor (or null)
mask
,
int
the x coordinate of the cursor's hotspot
hotspotX
,
int
the y coordinate of the cursor's hotspot
hotspotY
)

Constructs a new cursor given a device, image and mask data describing the desired cursor appearance, and the x and y coordinates of the hotspot (that is, the point within the area covered by the cursor which is considered to be where the on-screen pointer is "pointing").

public
Cursor(Device
the device on which to allocate the cursor
device
,
ImageData
the image data for the cursor
source
,
int
the x coordinate of the cursor's hotspot
hotspotX
,
int
the y coordinate of the cursor's hotspot
hotspotY
)

Constructs a new cursor given a device, image data describing the desired cursor appearance, and the x and y coordinates of the hotspot (that is, the point within the area covered by the cursor which is considered to be where the on-screen pointer is "pointing").

Method Summary

Modifier and TypeMethod and Description
pack-priv long
createCursor(byte[] sourceData, byte[] maskData, int width, int height, int hotspotX, int hotspotY, boolean reverse)

pack-priv void
public boolean

Returns:

true if the object is the same as this object and false otherwise
equals
(Object
the object to compare with this object
object
)

Overrides java.lang.Object.equals.

Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
public static Cursor
gtk_new(Device
the device on which to allocate the color
device
,
long
the handle for the cursor
handle
)

Invokes platform specific functionality to allocate a new cursor.

public int

Returns:

the receiver's hash
hashCode
()

Overrides java.lang.Object.hashCode.

Returns an integer hash code for the receiver.
public boolean

Returns:

true when the cursor is disposed and false otherwise
isDisposed
()

Implements abstract org.eclipse.swt.graphics.Resource.isDisposed.

Returns true if the cursor has been disposed, and false otherwise.
public String

Returns:

a string representation of the receiver
toString
()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.
Inherited from org.eclipse.swt.graphics.Resource:
disposegetDeviceignoreNonDisposedinitinitNonDisposeTrackingsetNonDisposeHandler

Field Detail

handleback to summary
public long handle

the handle to the OS cursor resource (Warning: This field is platform dependent)

Important Note

This field is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms and should never be accessed from application code.

Constructor Detail

Cursorback to summary
pack-priv Cursor(Device device)
Cursorback to summary
public Cursor(Device device, int style)

Constructs a new cursor given a device and a style constant describing the desired cursor appearance.

You must dispose the cursor when it is no longer required.

NOTE: It is recommended to use org.eclipse.swt.widgets.Display#getSystemCursor(int) instead of using this constructor. This way you can avoid the overhead of disposing the Cursor resource.
Parameters
device:Device

the device on which to allocate the cursor

style:int

the style of cursor to allocate

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if device is null and there is no current device
  • ERROR_INVALID_ARGUMENT - when an unknown style is specified
SWTError:
  • ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation
See Also
SWT#CURSOR_ARROW, SWT#CURSOR_WAIT, SWT#CURSOR_CROSS, SWT#CURSOR_APPSTARTING, SWT#CURSOR_HELP, SWT#CURSOR_SIZEALL, SWT#CURSOR_SIZENESW, SWT#CURSOR_SIZENS, SWT#CURSOR_SIZENWSE, SWT#CURSOR_SIZEWE, SWT#CURSOR_SIZEN, SWT#CURSOR_SIZES, SWT#CURSOR_SIZEE, SWT#CURSOR_SIZEW, SWT#CURSOR_SIZENE, SWT#CURSOR_SIZESE, SWT#CURSOR_SIZESW, SWT#CURSOR_SIZENW, SWT#CURSOR_UPARROW, SWT#CURSOR_IBEAM, SWT#CURSOR_NO, SWT#CURSOR_HAND, dispose()
Cursorback to summary
public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY)

Constructs a new cursor given a device, image and mask data describing the desired cursor appearance, and the x and y coordinates of the hotspot (that is, the point within the area covered by the cursor which is considered to be where the on-screen pointer is "pointing").

The mask data is allowed to be null, but in this case the source must be an ImageData representing an icon that specifies both color data and mask data.

You must dispose the cursor when it is no longer required.

Parameters
device:Device

the device on which to allocate the cursor

source:ImageData

the color data for the cursor

mask:ImageData

the mask data for the cursor (or null)

hotspotX:int

the x coordinate of the cursor's hotspot

hotspotY:int

the y coordinate of the cursor's hotspot

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if device is null and there is no current device
  • ERROR_NULL_ARGUMENT - if the source is null
  • ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask
  • ERROR_INVALID_ARGUMENT - if the source and the mask are not the same size, or if the hotspot is outside the bounds of the image
SWTError:
  • ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation
See Also
dispose()
Cursorback to summary
public Cursor(Device device, ImageData source, int hotspotX, int hotspotY)

Constructs a new cursor given a device, image data describing the desired cursor appearance, and the x and y coordinates of the hotspot (that is, the point within the area covered by the cursor which is considered to be where the on-screen pointer is "pointing").

You must dispose the cursor when it is no longer required.

Parameters
device:Device

the device on which to allocate the cursor

source:ImageData

the image data for the cursor

hotspotX:int

the x coordinate of the cursor's hotspot

hotspotY:int

the y coordinate of the cursor's hotspot

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if device is null and there is no current device
  • ERROR_NULL_ARGUMENT - if the image is null
  • ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the image
SWTError:
  • ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation
Since
3.0
See Also
dispose()

Method Detail

createCursorback to summary
pack-priv long createCursor(byte[] sourceData, byte[] maskData, int width, int height, int hotspotX, int hotspotY, boolean reverse)
destroyback to summary
pack-priv void destroy()

Overrides org.eclipse.swt.graphics.Resource.destroy.

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.

Parameters
object:Object

the object to compare with this object

Returns:boolean

true if the object is the same as this object and false otherwise

Annotations
@Override
See Also
hashCode
gtk_newback to summary
public static Cursor gtk_new(Device device, long handle)

Invokes platform specific functionality to allocate a new cursor.

Important Note

This method is not part of the public API for Cursor. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.

Parameters
device:Device

the device on which to allocate the color

handle:long

the handle for the cursor

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns an integer hash code for the receiver. Any two objects that return true when passed to equals must return the same value for this method.

Returns:int

the receiver's hash

Annotations
@Override
See Also
equals
isDisposedback to summary
public boolean isDisposed()

Implements abstract org.eclipse.swt.graphics.Resource.isDisposed.

Returns true if the cursor has been disposed, and false otherwise.

This method gets the dispose state for the cursor. When a cursor has been disposed, it is an error to invoke any other method (except dispose()) using the cursor.

Returns:boolean

true when the cursor is disposed and false otherwise

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.

Returns:String

a string representation of the receiver

Annotations
@Override