5

I'm working on a simple 2D game engine in Java, and having no trouble with FSEM, buffer strategies, and so on; my issue is with the mouse cursor. In windowed mode, I can hide the mouse cursor, no problem, by using setCursor() from my JFrame to set a wholly-transparent cursor. However, after a call to device.setFullScreenWindow(this) to go into FSEM, the mouse cursor comes back, and subsequent calls to setCursor() to set it back to my blank cursor have no effect. Calling device.setFullScreenWindow(null) allows me to get rid of the cursor again - it's only while I'm in FSEM that I can't get rid of it.

I'm working under JDK 6, target platform is JDK 5+.

UPDATE: I've done some more testing, and it looks like this issue occurs under MacOS X 10.5 w/Java 6u7, but not under Windows XP SP3 with Java 6u7. So, it could possibly be a bug in the Mac version of the JVM.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Adrian
  • 42,911
  • 6
  • 107
  • 99

7 Answers7

11

Try Creating a custom invisible cursor:

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Point hotSpot = new Point(0,0);
    BufferedImage cursorImage = new BufferedImage(1, 1, BufferedImage.TRANSLUCENT); 
    Cursor invisibleCursor = toolkit.createCustomCursor(cursorImage, hotSpot, "InvisibleCursor");        
    setCursor(invisibleCursor);
animuson
  • 53,861
  • 28
  • 137
  • 147
Janthoe
  • 111
  • 1
  • 2
5

One developer found a way around it by creating a one pixel cursor out of a transparent GIF.

http://sevensoft.livejournal.com/23460.html

I know you tried that, but his is specifically addressing the issue of full-screen mode, exactly as you say, so perhaps there's something he's done that you haven't.

davenpcj
  • 12,508
  • 5
  • 40
  • 37
  • That's more or less what I was doing, but I was creating my own 1-pixel transparent cursor image on-the-fly. I switched it to use a pre-made 1px transparent GIF, and it didn't help - still works in windowed mode but I cannot banish the cursor in full-screen mode. – Adrian Oct 10 '08 at 18:33
  • 1
    Maybe it's significant that he created/set the cursor only after entering FSEM. Example was on windows, as well, cursors are very platform specific, so you're probably right. – davenpcj Oct 13 '08 at 21:59
  • "Maybe it's significant that he created/set the cursor only after entering FSEM" I confirm that doing it *after* the setFullScreenWindow does work but not if call before. – Manuel Darveau Feb 18 '14 at 01:30
4

I think I've finally found the solution:

System.setProperty("apple.awt.fullscreenhidecursor","true");

This is an Apple-proprietary system property that hides the mouse cursor when an application is in full-screen mode. It's the only way I've found to fix it.

Adrian
  • 42,911
  • 6
  • 107
  • 99
  • @tristan2468 what problem did you have with it? Also what version of Java & what version of MacOS? You'll notice this is 5 years old now and may be out of date. – Adrian Apr 18 '13 at 14:58
  • It could be the age of the comment. It did not hide the cursor. Mountain Lion 10.8.3, Java: java version "1.6.0_43" Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-11M4203) Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode). – Nova Entropy Apr 18 '13 at 15:42
  • It should still work correctly but I haven't tested it on 10.8. According to Apple's developer documentation, the property is still valid (though supposedly it defaults to false). Make sure you set it before entering fullscreen mode. – Adrian Apr 18 '13 at 15:46
  • Yes. Still does not work. Am calling it before: frame.setUndecorated(true); gd.setFullScreenWindow(frame); This is an AWT Frame. – Nova Entropy Apr 18 '13 at 15:52
1

Here's what has been working for me:

Toolkit toolkit = Toolkit.getDefaultToolkit();

// get the smallest valid cursor size
Dimension dim = toolkit.getBestCursorSize(1, 1);

// create a new image of that size with an alpha channel
BufferedImage cursorImg = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);

// get a Graphics2D object to draw to the image
Graphics2D g2d = cursorImg.createGraphics();

// set the background 'color' with 0 alpha and clear the image
g2d.setBackground(new Color(0.0f, 0.0f, 0.0f, 0.0f));
g2d.clearRect(0, 0, dim.width, dim.height);

// dispose the Graphics2D object
g2d.dispose();

// now create your cursor using that transparent image
hiddenCursor = toolkit.createCustomCursor(cursorImg, new Point(0,0), "hiddenCursor");

Granted, I haven't tested it on Mac (yet), only Windows. But when I used the common methods I was getting the cursor as black box, so I use the code above the create a transparent box and set it as the cursor instead. Of course you have to use the setCursor method on an AWT object (such as your app's Frame) to set this hiddenCursor. Here is my hideMouse method ('fr' is my Frame):

public void hideMouse(boolean hide) {
    if(hide) {
        fr.setCursor(hiddenCursor);
    } else {
        fr.setCursor(Cursor.getDefaultCursor());
    }
}
Ricket
  • 33,368
  • 30
  • 112
  • 143
0

I don't know if this knowledge applies but in a old VB6 app I had the same problem and I got rid of it moving the cursor out of the screen giving it some very large values.
Hope it helps.

Antonio Louro
  • 528
  • 1
  • 5
  • 14
  • The problem is, I need the mouse input, I just want to hide the cursor image on the screen. – Adrian Oct 10 '08 at 14:41
0

If you're running only on Windows, it looks like you'll need to call ShowCursor(FALSE) through JNI. At least, to make the cursor hide complete.

Here's some code which creates the 1x1 cursor. It works for me, though I still get a 1x1 cursor.

 Toolkit toolkit = Toolkit.getDefaultToolkit();
 Dimension dim = toolkit.getBestCursorSize(1,1);
 transCursor = toolkit.createCustomCursor(gc.createCompatibleImage(dim.width, dim.height),
     new Point(0, 0), "transCursor");
 ((Component)mainFrame).setCursor(transCursor);
seisyll
  • 168
  • 1
  • 3
  • This is almost exactly what I'm doing, and while it works perfectly in windowed mode, it doesn't work in full-screen mode. The cursor still shows up until I leave full-screen mode, then I'm able to hide it again, using the same technique you described. – Adrian Oct 10 '08 at 20:24
0

Specifically for your Mac problem, through JNI you could use the following:

Quartz Display Services Reference - CGDisplayHideCursor

slf
  • 22,595
  • 11
  • 77
  • 101