Hourglass cursor in swing

I

Ike

Does anyone have or know of a quick example site showing how to implement,
using Swing, an hourglass cursor while something is being processed,
returning to the default cursor afterwards? I know this is a threading
issue.

Thanks, Ike
 
M

Michael Rauscher

Hello Ike,
Does anyone have or know of a quick example site showing how to implement,
using Swing, an hourglass cursor while something is being processed,
returning to the default cursor afterwards? I know this is a threading
issue.

Thanks, Ike

my English isn't the best, but I'll try it:

I'd suggest to wrap your process within a self-written Command class.

The Command class would notify CommandListeners about CommandEvents. A
CommandEvent may be of one of three different types (e.g. CMD_START,
CMD_STOP, CMD_ABORT).

The Command class notifies it's listeners about command state changes
(notifyStart(), notifyStop(), notifyAbort()) and offers a method run,
that is intended to start your process.

In the Command's run method, you first notify your listeners about the
process-start (notifyStart()). Then you start your process. After your
process is done you call notifyStop. If you catch an exception, call
notifyAbort.

Your Swing-Component only has to implement the CommandListener
interface, which has one method: commandStateChanged( CommandEvent evt )

Now you can do anything within the commandStateChanged-Method: setting
hourclass cursor if the event is of type CMD_START, returning to default
cursor if the event is of type CMD_STOP or CMD_ABORT. Display an alert
box if the event is of type CMD_ABORT and so on.

cheers

Michael
 
K

Karl von Laudermann

Ike said:
Does anyone have or know of a quick example site showing how to implement,
using Swing, an hourglass cursor while something is being processed,
returning to the default cursor afterwards? I know this is a threading
issue.

Well, setting and restoring the cursor is as easy as executing the
following statements:

myComponent.setCursor(new Cursor(Cursor.WAIT_CURSOR));

// Do stuf...

myComponent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

where myComponent is a Component (or subclass). The mouse cursor will
be shown as the wait cursor while the mouse is over myComponent. It
can of course be the main window of your app, so the cursor will be
the wait cursor while over any part of the main app window.
 
C

Christian Kaufhold

Karl von Laudermann said:
Well, setting and restoring the cursor is as easy as executing the
following statements:

myComponent.setCursor(new Cursor(Cursor.WAIT_CURSOR));

// Do stuf...

myComponent.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

where myComponent is a Component (or subclass). The mouse cursor will
be shown as the wait cursor while the mouse is over myComponent. It
can of course be the main window of your app, so the cursor will be
the wait cursor while over any part of the main app window.

unless an explicit Cursor has been set for the component the mouse cursor
(different term?) is currently over or any of its other ancestors.





Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top