Hiding the cursor

Hi

How do I hide the mouse cursor in awt/swing? I would like to draw my own graphic.

Would it be better to hide the cursor and draw an image based on the cursor, or to create a custom mouse cursor and set it to that?

Thanks

Image cursorImage = Toolkit.getDefaultToolkit().getImage(“xparent.gif”);
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point( 0, 0), “” );
setCursor( blankCursor );

I hope this works, it did for me. If you didn’t want a cursor at all, make xparent transparent. This may not be the best way but for small apps it may be ok. Worth a try.

I create an Image in code with a 1x1 transparent pixel. No need to save that to a file, just code it.

Thanks, that’s what I needed :slight_smile:

setCursor(Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB),new Point(0,0),""));

:wink:

Although OS X happily ignores this :slight_smile:

[quote]Although OS X happily ignores this :slight_smile:
[/quote]
oNyx’s version works for me under OS X with a JOGL canvas. The cursor change is the last thing that happens when loading (and the canavas is visible when it is hidden).

If the application loses focus, the cursor reverts back to the default when focus is regained and has to be manually reset.

Will.

This mac issue (clearly a bug) sucks so much. I’m having that problem with fuzetsu on mac.

Was that ever fixed? Guess not.

And why isnt there a default cursor for that. Its not that unusual, is it? Ah ok… found the answer myself…

“We’ve decided against doing this: its merely a hack so that the customer can
then draw their own cursor. What they really want is a way to set the cursor
to an arbitrary bitmap, which we promise to do in 1.2.”

Yea, right… what I really want… creating some transparent image looks more like a hack to me.

* oNyx throws the first rock

9+ years later and its still an issue. I cant believe it. Reporting bugs is such a bad joke when it comes to java. (Thats one of the two things which suck about java… the other one are distribution issues.)

I find the bug reports are not a joke. You have to realize just how huge Java is and that the people evaluating the bug reports often are seeing things from a different perspective and may not get the point.

I can easily see how the evaluator came to the conclusion that custom cursors were the “real” problem, and quite frankly I think I would come to the same evaluation. It does solve both problems… getting user definable cursors AND hiding the cursor. I don’t think it is a hack, it is in fact a clean solution. Why have a way to set the cursor to a custom image and a different way to set the cursor to not appear? At the OS level there it could be that cursor hiding is implemented using a “empty” cursor image anyway :slight_smile:

Have you filed a bug report with Apple about the cursor reset on focus gained?

I find the bug reports are not a joke. You have to realize just how huge Java is[…]

I know how big java is and I also know that that’s the reason why it takes years (till forever) to fix things.

Why have a way to set the cursor to a custom image and a different way to set the cursor to not appear?

There are a lot of predefined cursors. Why not have a predefined one for this case?

Have you filed a bug report with Apple about the cursor reset on focus gained?

No. I dont have a mac myself. Writing a bug report would be useless. They would decide that it lacks detail and it would go directly to the trash bin like my other bug report. I rather bitch about the whole issue… its more fun (and equally useless).

[quote=“oNyx,post:10,topic:20437”]
Yes, they should have that. Is there an enhancement request?

I would file bugs anyway… there is nothing I hate more that users that don’t tell me what is wrong with my code… they just bitch about stuff not working… but they won’t tell the people that can do something about it. If nothing happens, fine, not every one of person X’s problems can be a top priority… but if you haven’t bothered to ask for a fix at all then you shouldn’t expect to get one.

Instead of telling me the same stuff you already told me 2 years ago you could have written a bug report yourself.

If something is useless and no fun at all (like burning my fingers on a hot plate), I stop doing it. End of story.

I believe that it isn’t guaranteed that the BufferedImage will start off transparent (since Java 1.1). Enabling Quartz on OS X 10.4 certainly changing the default fill for me. It is probably worth considering setting the background colour to transparent & using clearRect on it.

Edit: Knew I’d seen it stated somewhere :slight_smile: