How do I change the cursor shape?

Using the following example you can change the shape of cursor in your Swing desktop application. Just create a Cursor object and assign it to your JFrame instance. A collections of cursor shapes defined in the java.awt.Cursor class.

package org.kodejava.example.swing;

import javax.swing.*;
import java.awt.*;

public class CursorExample extends JFrame {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                CursorExample form = new CursorExample();
                form.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                form.setSize(250, 250);

                // Here we create a hand shaped cursor!
                Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
                form.setCursor(cursor);

                form.pack();
                form.setVisible(true);
            }
        });
    }
}