Enlarged cursor in Java

Is it possible to create a larger cursor (by method createCustomCursor()

) than the predefined 32x32 on Windows (e.g. 64x64 or even larger)?

Toolkit toolkit = Toolkit.getDefaultToolkit();
final Image cursor = toolkit.getImage(getClass().getClassLoader().getResource("images/cursor.png"));
toolkit.getBestCursorSize(64, 64);
Cursor mycursor=toolkit.createCustomCursor(cursor, new Point(0,0), "cursor");
setCursor(mycursor);

      

I tried the following:

 Cursor emptyCursor = Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), "empty"); 
        setCursor(emptyCursor);

        this.addMouseMotionListener(new MouseMotionListener(){
            public void mouseDragged(MouseEvent e) {
            }

            public void mouseMoved(MouseEvent e) {
                xCursor = e.getX();
                yCursor = e.getY();
                repaint();
                //e.consume();
            }
        });

 public void paint( Graphics g ) {
           g.drawImage(cursor, xCursor, yCursor, null);
       }

      

But that doesn't work, the whole GUI disappears and the cursor is drawn at every point, so I need to remove it this way?

+3


source to share


2 answers


Is there a way to make the cursor smaller than the predefined 32x32? If so, make the cursor so tiny you really won't notice it, or make the cursor transparent ... THEN, just move the image to the coordinates of the current location of the cursors each (enter your desired time interval here)



+1


source


It seems that Windows only allows pointers of 32x32 pixel size, so if you want a different size to work around it.

To make a larger cursor, I believe this will work:



  • Create a custom cursor that is completely transparent.

  • Use mouseMotionListener

    to get the position of the cursor.

  • Draw an image of the cursor at the position of the real (transparent) cursor.

+1


source







All Articles