dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
May 8, 2002

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Set the Cursor for Your Components


All AWT component classes have a setCursor() method that allows for dynamically setting the cursor for a particular component and any subcomponents.

For example, if you set the cursor for a Panel, all the components added to that Panel will inherit the Panel's cursor unless the components explicitly override it. Once a cursor is set for a component, the cursor will be automatically used when the pointer enters the component (as long as the component is visible and enabled).

To set the cursor for a component, get an instance of java.awt.Cursor. This class contains many predefined cursors that are accessed using type constants such as WAIT_CURSOR or HAND_CURSOR. You can retrieve Cursor objects by using one of the constructors or the static method Cursor.getPredefinedCursor(). This code sample displays a busy cursor (such as a watch icon) while an operation completes:
 
myComponent.setCursor(Cursor.getPredefinedCursor
(Cursor.WAIT_CURSOR));
//do stuff
myComponent.setCursor(null);
//use default cursor inherited from parent Component

Note that these methods need to be called from within the Swing event thread. If you call them from another thread, use the SwingUtilities.invokeLater() method to do so. You can also call getCursor() on the component if you need to save and restore the previous cursor afterwards. Setting the cursor to null may not be appropriate for components that already have a custom cursor defined.
Ramneek Handa
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date