What makes java.awt.cursor special? My assumption is that when you set a cursor in a Component, some kind of native code is used to draw the mouse cursor in some special really fast way. Is this accurate?
I ask because I have a specific problem. I have a game that can be resized to various sizes as either a window or a full-screen application. The user could conceivably sit there and resize the window repeatedly for no apparent reason.
In general, this is fine. I’ve gone to great lengths to make my custom Swing components and layouts resize well. But I also have a custom cursor for one part of the game. It changes to different images depending upon what action you can take.
As it is right now, the cursor doesn’t get resized when the window is resized. This is ridiculous as it’s possible to have a giant cursor in a very small window, which makes the cursor bigger than the in-game objects. I’ve come up with two possible solutions:
-
Make the cursor invisible and draw my own custom cursor stretched however it should be stretched.
-
Continue using the Component.setCursor method. Add some kind of ComponentListener/WindowListener to the JFrame to watch for resizing. When the JFrame is resized, a new cursor image is created at the right size and made into the new cursor.
I slightly prefer solution 1. I will have more control over any custom cursor classes I write than over the cursor class provided by Java. Stretching the cursor image during drawing is more in synch with the rest of my code. And I don’t kneed to mess around with having another listener on the JFrame.
However, if there is some sort of hardware acceleration when using the Component.setCursor method, I might be better off with option 2, even if I don’t like it.
Any opinions? I figured I get some ideas about this before writing a bunch of code.