如何使用JOGL2隐藏鼠标光标?

发布于 2024-10-05 10:07:38 字数 161 浏览 6 评论 0原文

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

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

I'm using JOGL2 and the NativeWindow APIs to write an app in Java. How can I hide the mouse cursor?

[EDIT]
I'm not using JFrame to create a window but rather GLWindow from JOGL. GLWindow does not have a setCursor method. Is this still possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

眉黛浅 2024-10-12 10:07:38

正如您(thekidder)所说,GLWindow没有这种功能,所以我会在Frame(或JFrame)内使用GLCanvas >)像这样(就像AlexR写的):

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);
}

As you (thekidder) say GLWindow does not have that capability so I would use GLCanvas inside a Frame (or JFrame) like this (like AlexR wrote):

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);
}
垂暮老矣 2024-10-12 10:07:38

此后,这已在 JOGL2 中使用 NEWT(GLWindow 对象)实现。请参阅https://jogamp.org/bugzilla/show_bug.cgi?id=409(在thekidder的回答中引用)。

你可以这样做:

glWindow.setPointerVisible(false);

This has since been implemented in JOGL2 using NEWT (a GLWindow object). See https://jogamp.org/bugzilla/show_bug.cgi?id=409 (referenced in thekidder's answer).

You can do it like so:

glWindow.setPointerVisible(false);
抽个烟儿 2024-10-12 10:07:38

如果鼠标位于应用程序窗口区域,您可以将任何图像设置为自定义光标。使用 1x1 像素的透明图像。我用过它 - 效果很好。它是常规 API,没有 JOGL,没有本机代码。

If mouse is in the area of application window you can set any image as a custom cursor. Use transparent image 1x1 pixel. I used it - works fine. It is regular API, no JOGL, no native code.

季末如歌 2024-10-12 10:07:38

经过进一步搜索后,发现 JOGL2 中的 NEWT 窗口尚未实现此功能。 JOGL 的 bugzilla 上有一个增强请求: http://jogamp.org/bugzilla/show_bug .cgi?id=409

After some further searching it appears that this is not implemented for NEWT windows in JOGL2 yet. There is an enhancement request filed on JOGL's bugzilla: http://jogamp.org/bugzilla/show_bug.cgi?id=409

Oo萌小芽oO 2024-10-12 10:07:38

目前使用 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)

At the current time with 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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文