Invisible cursor and X 11

Trying to hide the cursor with JDK1.5.0 on linux, I get

Exception in thread “main” java.lang.ExceptionInInitializerError
at apollo.Surface.(Surface.java:59)
at test.TestLevel.run(TestLevel.java:69)
at test.TestLevel.main(TestLevel.java:54)
Caused by: java.lang.IndexOutOfBoundsException: invalid hotSpot
at sun.awt.CustomCursor.(CustomCursor.java:61)
at sun.awt.X11CustomCursor.(X11CustomCursor.java:26)
at sun.awt.X11.XCustomCursor.(XCustomCursor.java:27)
at sun.awt.X11.XToolkit.createCustomCursor(XToolkit.java:742)
at apollo.CursorManager.createInvisibleCursor(CursorManager.java:68)
at apollo.CursorManager.(CursorManager.java:37)
… 3 more

The code looks like this:
private static Cursor createInvisibleCursor()
{
// Create the invisible cursor
MemoryImageSource memIm = new MemoryImageSource(1, 1, new int[] { 0 }, 0, 1);
Component c = new Component() { };
Image im = c.createImage(memIm);
Point spot = new Point(1, 1);
return c.getToolkit().createCustomCursor(im, spot, INVISIBLE_CURSOR_NAME);
}

Has anybody experienced the same problem ? Any solution ?

It looks like you’re creating a 1x1 image, and trying to use 1,1 point as a hotspot. (1,1) is out of bounds for a 1x1 image.
You should use 0,0 instead.

Thanks,

Actually what surprised me is that the same code worked with JDK 1.4.2 (Windows). I guess something has changed in the JDK 1.5 that now exposes my misuse of the hotspot.

I’m guessing that the awt team has fixed some bug, so now the exception is thrown if the hotspot is invalid…

But… it shouldn’t be invalid!!! A hotspot can be anywhere relative to the actual image really… even outside of it.

Cas :slight_smile:

you have a Point there.

That’s why I shouldn’t be allowed to answer non-java2d related questions, at least, w/o reading the javadoc first =)

Looks like it could be a new bug, likely to be caused by XAWT, assuming the Dimension returned by getBestCursorSize is more than 0x0- see the javadoc for createCustomCursor.

Try running your app with -Dawt.toolkit=sun.awt.motif.MToolkit
to see if it works with motif toolkit.