Search code examples
javajoglmouse-cursor

How to hide mouse cursor using JOGL2?


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?


Solution

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