File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Change Image Of Mouse Cursor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Change Image Of Mouse Cursor" Watch "Change Image Of Mouse Cursor" New topic

Change Image Of Mouse Cursor

merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
Is it possible to change the default cursor to an image? .... ...something like we have in MS Paint.
the Cursor class has shapes like the HourGlass etc. which is good
but can the cursor be associated to an image?
I am trying to write an Whiteboard Application and when the user would click on the pencil button , i want the pencil image to appear instead of the cursor .... How can i achive this using the Cursor class?
Joe Coughlin

Joined: Jun 16, 2005
Posts: 2
We have used :

Toolkit toolkit = getToolkit();
// Wherever your image is:
Image cursorImage = toolkit.getImage(dataDirectory + File.separator
+ "icons" + File.separator + "circleCursor.gif");

Point cursorHotSpot = new Point(15, 15);

Cursor lightPenCursor = toolkit.createCustomCursor(cursorImage,
cursorHotSpot, "lightPenCursor");

setCursor(lightPenCursor); //Within a JPanel

I hope this helps.
merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
Thanks a lot Joe. That information really helped.
I agree. Here's the link:
subject: Change Image Of Mouse Cursor
It's not a secret anymore!