Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Java Tutorials



Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java Notes


Sometimes you want to change the cursor to show the user that something is different. For example, you might want to show a wait cursor (typically an hour glass or watch) when the program is working on something that will take a long time. Or you might want to change to a crosshairs cursor when the user must indicate a pixel to draw on.

The cursor is attached to a component

A change in the cursor occurs only when it is over the component that has set it. If you want to set the cursor for the whole window (JFrame), you need to set it for the content pane of the window.

Using the java.awt.Cursor class

You will need to import java.awt.Cursor.

The predefined cursors

There are a number of predefined cursors. Java has names for each of the predefined cursors, but the exact appearance of each cursor depends on the system that it is running on. Eg you may see the wait cursor as an hourglass in Windows, and as a wristwatch on the Macintosh (See Look and Feel).

These predefined constants in the Cursor class are not cursors, they are int codes that are used as a parameter in the Cursor.getPredefinedCursor(int) method.

int typedescription
Cursor.DEFAULT_CURSORdefault cursor
Cursor.CROSSHAIR_CURSORcrosshair cursor
Cursor.HAND_CURSORhand cursor
Cursor.MOVE_CURSORmove cursor
Cursor.WAIT_CURSORwait cursor
Cursor.TEXT_CURSORtext cursor
Cursor.E_RESIZE_CURSOReast-resize cursor
Cursor.N_RESIZE_CURSORnorth-resize cursor
Cursor.NE_RESIZE_CURSORnorth-east-resize cursor
Cursor.NW_RESIZE_CURSORnorth-west-resize cursor
Cursor.S_RESIZE_CURSORsouth-resize cursor
Cursor.SE_RESIZE_CURSORsouth-east-resize cursor
Cursor.SW_RESIZE_CURSORsouth-west-resize cursor
Cursor.W_RESIZE_CURSORwest-resize cursor

The Container setCursor(. . .) method

After you call a component's setCursor(...) method, the cursor will be changed. The parameter to setCursor(. . .) is a Cursor object. You can create your own cursors, but you will probably be satisfied using the predefined cursors.

Example - Setting the wait cursor for a frame (window)

   Container c = frame.getContentPane();  // get the window's content pane
   . . . // do something that takes a long time

Custom and other system cursors

You can create your own cursors (see Toolkit.createCustomCursor()) or use cursors from the local system (see Cursor.getSystemCustomCursor(String)).
Ask programming questions?



Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (post your own) View All Comments Latest 10 Comments:

u provide a easy way to understanding the things.
I got the solution of my problem in very convinient manner.

Thank You

Posted by Paras Jain on Monday, 06.8.09 @ 08:53am | #88319

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]