(LWJGL) Hide mouse cursor without Mouse.setGrabbed?

Is there a way to do it without calling Mouse.setGrabbed(true)? I want to hide the mouse only while inside the window. I still want to be able to use the exit button, or be able to move the cursor outside of the window.

Thanks,
| Nathan

You can always set the mouse cursor to a blank image while inside the container

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

Rorkien’s answer isnt LWJGL, but he is right. Just use a blank cursor.

Yup, use the Mouse.setNativeCursor() method to set a blank cursor and you’ll get the behaviour that you are looking for.

Oh, theres a cursor method on LWJGL?

Gee, i really gotta drop into it :stuck_out_tongue:

How do I just set it to be blank?

I tried just going


		try {
			Mouse.setNativeCursor(new Cursor(0, 0, 0, 0, 0, null, null));
		} catch (LWJGLException e) {
			e.printStackTrace();
		}

but then I get this


Exception in thread "main" java.lang.NullPointerException
	at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:188)
	at org.lwjgl.NondirectBufferWrapper.wrapBuffer(NondirectBufferWrapper.java:111)
	at org.lwjgl.input.Cursor.<init>(Cursor.java:89)
	at com.natekramber.Main.init(Main.java:56)
	at com.natekramber.Main.<init>(Main.java:36)
	at com.natekramber.Main.main(Main.java:21)

| Nathan

I dont think Cursor has that many arguments :stuck_out_tongue:
Anyways, you can try this using the method i posted with the LWGJL method (Im not sure as well)

Mouse.setNativeCursor(Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), "cursor"));

Cursor is a LWJGL class, too :slight_smile:

The setNativeCursor method takes a LWJGL cursor, not a default Java one.

| Nathan

Hmph. :emo:

Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, java.nio.IntBuffer images, java.nio.IntBuffer delays) 
          Constructs a new Cursor, with the given parameters.

Have you tried using width/height/numImages > 0? For a NPE it gotta be something like that.
Engage Trial & Error mode

Yep.

I’m assuming it’s the last two parameters that are causing problems, but I don’t really know how to fix that.

| Nathan

EDIT: Well, I just found the answer here from princec! Thanks for helping with my problem, even though you didn’t even know it :wink: