How to hide the mouse cursor using JOGL2?

I am using JOGL2 and the NativeWindow API to write a Java application. What is the best / easier way to hide the mouse cursor?

[EDIT] I am not using JFrame to create a window, but rather GLWindow from JOGL. GLWindow does not have a setCursor method. Is it possible?

+3
source share
5 answers

As you said (thekidder), it GLWindowdoesn’t have this possibility, so I would use it GLCanvasinside Frame(or JFrame), like this (for example, 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);
}
+4
source

JOGL2 NEWT ( GLWindow). . https://jogamp.org/bugzilla/show_bug.cgi?id=409 (. ).

:

glWindow.setPointerVisible(false);
+2

, . 1x1. - . API, JOGL, .

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

Source: https://habr.com/ru/post/1777756/


All Articles