这里就是一直为我工作:
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对象(比如你的应用程序的Frame)上使用setCursor方法来设置这个hiddenCursor。这里是我的hideMouse方法(“FR”是我的框架):
public void hideMouse(boolean hide) {
if(hide) {
fr.setCursor(hiddenCursor);
} else {
fr.setCursor(Cursor.getDefaultCursor());
}
}
的问题是,我需要鼠标输入,我只是想隐藏光标图像在屏幕上。 – Adrian 2008-10-10 14:41:57
对不起,误解了你:( – 2008-10-10 17:59:53