Skip to main content

change mouse cursor?

2 replies [Last post]
Anonymous

hi

is anybody know how to change the mouse cursor, using our own image, not the standard one defined in java.awt.Cursor (N,NE,E,S,SE,hand,etc).

my question is:
- what format the image must be gif,jpeg,png?
- what resolution it need 16x16,32x32, etc?
- how to determine hit point?
- how to load it and use it?

any pointer, doc, tutorial, or sample source?

Regards
Tonny

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shan-man
Offline
Joined: 2006-02-17

Hi Tonny,

> hi
>
> is anybody know how to change the mouse cursor, using
> our own image, not the standard one defined in
> java.awt.Cursor (N,NE,E,S,SE,hand,etc).
>
> my question is:
> - what format the image must be gif,jpeg,png?

I believe all of those formats are supported.

> - what resolution it need 16x16,32x32, etc?

You can ask the method Toolkit.getBestCursorSize(int, int).

> - how to determine hit point?

You can specify that when you create a cursor.

> - how to load it and use it?

First, you load the image that you want to use for the cursor. Loading an image is easy and you can read about it under "Working with Images" in my article:
http://java.sun.com/products/jfc/tsc/articles/swing2d/index.html#COOL_EF...

Then you can use Toolkit to create the cursor and the setCursor method to change the cursor for a particular component:
[code]
// create a cursor for 'image' with the hotspot at 0, 0.
Cursor curs = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), "MyCursor");

// set this cursor on a component
comp.setCursor(curs);
[/code]
Regards,
Shannon

>
> any pointer, doc, tutorial, or sample source?
>
> Regards
> Tonny

Anonymous

Thank for the info

Regards
Tonny
http://www.kiyut.com