This section illustrates you how to change the appearance of the cursor.
Using SWT we can change the style of cursor, by using the class Cursor of package org.eclipse.swt.graphics. To show the hand cursor, we have defined the SWT.CURSOR_HAND in the constructor of Cursor. On clicking the Hand cursor button, the Event class is called which change the cursor using the method setCursor(cursor1).
To show the cursor which is created from the source, we have defined the class PaletteData. The method getSystemColor() returns the defined standard color. The class ImageData provides the description of the image. The method setPixel(i, j, 1) sets the pixel value and on clicking the button, a rectangular cursor will be appeared.
To show the cursor created from the selected image, we have used the class FileDialog to navigate the file system and select the file name. The method setFilterExtensions() set the file extensions which the dialog will use to filter the files. To make the dialog visible, the method fileDialog.open() is used. On clicking the image cursor button, the dialog is displayed to select the image. On selecting an image, the cursor shows the selected image.
Here is the code of CreateCursorExample.java
Output will be displayed as:
On clicking the the first button, the hand cursor will be appeared. The second button displays the rectangular cursor and the last one shows the cursor creating from the image.
Posted on: October 3, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles