EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Showing the wait cursor


Author: Zafir Anjum

Given a component you can use setCursor to change the cursor. E.g.


((Component)comp).setCursor(Cursor.getPredefinedCursor(Frame.WAIT_CURSOR));

This will cause the mouse cursor to change to the wait cursor whenever it is over the component but not outside of it. To change the cursor for the entire frame, you might think that the following would work ...


frame.setCursor(Cursor.getPredefinedCursor(Frame.WAIT_CURSOR));

Unfortunately it doesn't. You actually have to do three things, to make this happen.

1. Change the cursor for the glass pane.
2. Make the glass pane visible.
3. Add a mouse listener


frame.getGlassPane().addMouseListener( new MouseAdapter() {});
frame.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
frame.getGlassPane().setVisible(true);


Note that while the glass pane is visible, none of the controls in the frame receive mouse message, they do however receive keyboard events.

To remove the wait cursor, simply set the visibility flag of the glass pane to false.

Also, note that simply calling setCursor() doesn't actually change the cursor. The change is delayed till the next mouse click or movement.

Check out the bug 4160474 in the Java Developer Connection. It covers this problem and has apparently been fixed.

Posted On: 20-Jan-1999

internet.commerce



Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers