how-to

Others

How to set cursor

For working with Cursor class you need to use:

import java.awt.Cursor;

Cursor could be changed for every object that is an instance of java.awt.Window class. That object could be for example JFrame, or one JButton, JLabel only.

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

This example shows busy wait cursor (as clock).

For return to default cursor you could call:

setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );

or directly:

setCursor( Cursor.getDefaultCursor() );

It is recommended to use try..finally block.

try {
  setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );

  do some action;
}
finally {
  setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
}

In your application you could use this predefined cursors (JDK 1.6):