开发者

How to hide mouse cursor using JOGL2?

开发者 https://www.devze.com 2023-01-28 04:47 出处:网络
I\'m using JOGL2 and the NativeWindow APIs to write an app in Java. How can Ihide the mouse cursor? [EDIT]

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. GLWin开发者_C百科dow does not have a setCursor method. Is this still possible?


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


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


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.


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


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号