Click to See Complete Forum and Search --> : JAVA: changing the cursor


Dan Hopkins
January 22nd, 1999, 01:43 PM
From a post from Zafir Anjum regarding chaning the mouse cursor:



note that simply calling setCursor() doesn't actually change the cursor. The change is delayed till the next mouse click or movement.


This does indeed seem to be the case.

My question is should it then not be possible to turn around post a mouseEvent such as mouseMove. I have tried this by posting Directly to the EventQueue,

and by calling dispatchEvent on the object in question directly. But to no avail.

Zafir Anjum
January 22nd, 1999, 03:43 PM
It should certainly be possible to force the change. You'd have to experiment a

little bit.


Meantime if you are not afraid to use undocumented / deprecated stuff here's a

much simple way of changing the cursor. Note: Make sure you use this only for

top level windows e.g. JFrame.


frame.getPeer().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));


This basically calls the native OS which affects the change immediately.