Mega Code Archive

 
Categories / Java Tutorial / SWT
 

Create Cursor from an Image

import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class CursorImageCreate {   public static void main(String[] args) {     final Display display = new Display();     final Shell shell = new Shell(display);     shell.setSize(150, 150);          Cursor cursor = new Cursor(display, new Image(display,"yourFile.gif").getImageData(), 0, 0);     shell.setCursor(cursor);     shell.open();     while (!shell.isDisposed()) {       if (!display.readAndDispatch())         display.sleep();     }     cursor.dispose();     display.dispose();   } }