How do I change the cursor shape?

Category: javax.swing, viewed: 1580 time(s).

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 mainForm = new CursorExample();
                mainForm.setDefaultCloseOperation(
                    JFrame.EXIT_ON_CLOSE);
                mainForm.setSize(250, 250);
 
                // Here we create a hand shaped cursor!
                Cursor cursor = new Cursor(Cursor.HAND_CURSOR);
                mainForm.setCursor(cursor);
 
                mainForm.pack();
                mainForm.setVisible(true);
            }
        });
    }
}
 
 
Bookmark this example!  

Most Viewed Examples

Google

100 Top & Latest


eXTReMe Tracker
visitor stats