Cannot add MouseListener to java.awt.Canvas with lwjgl on Windows

I’m trying to determine if this is a known issue.

I’ve created a java.awt.Canvas and I’ve put it into a Frame. It’s being initialized with Display.setParent.

I’ve been trying to add a MouseListener to this canvas so that I can trap the mouseEnter and mouseExit events. It works on Mac OS X and Linux but I cannot get it to work on:

  • Windows XP 2002 running Java 1.6.0_20
  • Windows 7 running Java 1.6.0_25

I’ve also tried attaching the listener to the Frame and to a Panel containing the Canvas but no luck.

For a reproducer turn on the Java Console and try the webstart app:
http://www.java-gaming.org/index.php/topic,24487.0.html

If the listener is working you should see “cursor entered/exited lwjgl canvas” on stdout whenever you enter/exit the canvas.

Does lwjgl have its own mouse and key listener?

Tracked down the cause:

http://www.sfml-dev.org/forum/viewtopic.php?t=4938&postdays=0&postorder=asc&start=15

[quote]Java uses the GWLP_USERDATA field to store a pointer to an AWTComponent object, which apparently is required so the Canvas can cooperate with AWT correctly. SFML [and lwjgl on Windows only] overrides that field to store its own Window object pointer, which will of course break AWT functionality.
[/quote]
src/native/windows/org_lwjgl_opengl_Display.c, line 89

Don’t have a good solution though without writing native code. Since I’m only interested in mouse movement I could use the MouseInfo class that returns the cursor location in absolute coordinates.