Using Cursors : Cursor « Swing « Java Tutorial






Cursor myCursor = new Cursor(Cursor.TEXT_CURSOR);
Cursor myCursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class CreatingCursors {
  public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is the Window Title");
    Toolkit theKit = aWindow.getToolkit(); // Get the window toolkit
    Dimension wndSize = theKit.getScreenSize(); // Get screen size
    // Set the position to screen center & size to half screen size
    aWindow.setBounds(wndSize.width / 4, wndSize.height / 4, // Position
        wndSize.width / 2, wndSize.height / 2); // Size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    aWindow.setVisible(true); // Display the window
  }
}








14.115.Cursor
14.115.1.Using Cursors
14.115.2.Change the cursor shape
14.115.3.Changing the Cursor
14.115.4.Change Cursor in a thread for animation