これが私のために働いているものです:
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");
確かに、私は (まだ) Mac ではテストしておらず、Windows だけでテストしています。しかし、一般的な方法を使用すると、カーソルがブラック ボックスとして取得されたので、上記のコードを使用して透明なボックスを作成し、代わりにカーソルとして設定します。もちろん、AWT オブジェクト (アプリのフレームなど) で setCursor メソッドを使用して、この hiddenCursor を設定する必要があります。これが私のhideMouseメソッドです(「fr」は私のフレームです):
public void hideMouse(boolean hide) {
if(hide) {
fr.setCursor(hiddenCursor);
} else {
fr.setCursor(Cursor.getDefaultCursor());
}
}