如何使用JOGL2隐藏鼠标指针?

3

我正在使用JOGL2和NativeWindow API编写Java应用程序。如何隐藏鼠标光标?

[编辑]
我没有使用JFrame创建窗口,而是使用JOGL中的GLWindow。GLWindow没有setCursor方法。这仍然可能吗?

5个回答

5

正如你所说的,GLWindow没有这个功能,因此我会像AlexR所写的那样,在Frame(或JFrame)中使用GLCanvas

public static void main(String... args) {

    // create the cursor
    Toolkit t = Toolkit.getDefaultToolkit();
    Image i = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    Cursor noCursor = t.createCustomCursor(i, new Point(0, 0), "none"); 

    // try it with a normal frame
    Frame f = new Frame();

    // create the GLCanvas and add it to the frame
    GLCanvas canvas = new GLCanvas();
    frame.add(canvas);

    f.setCursor(noCursor);
    f.setSize(400, 200);
    f.setVisible(true);
}

NP,那么你不能使用解决方案吗?你必须使用GLWindow吗? - dacwe
我可以做到,只是想确认一下我的选择;) - thekidder
这个答案已经不准确了,请查看我的答案以获取一个新的解决方案。 - Mike Stone

2

1
如果鼠标在应用程序窗口区域内,您可以将任何图像设置为自定义光标。使用透明图像1x1像素。我用过它 - 运行良好。这是常规API,没有JOGL,也没有本地代码。

0

0

目前使用 NEWT GLWindow:

window = GLWindow.create(caps);

...

window.requestFocus();
window.setAlwaysOnTop(true); // i think, be on top is good than mouse is jailed
window.setUndecorated(true); // remove window borders (if u want)
window.setPointerVisible(false); // hide cursor
window.confinePointer(true); // jail inside (cursor will be limited to window borders)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接