hourglass pattern?

T

timasmith

Is there a pattern for placing hourglasses on and off through GUI apps?

My actions are not necessarily near the code that created the button

someButton.addListener(actionListener);

I suppose I have to toggle the hour glass withing the action listener,
being careful to catch exceptions and turn it off?

Any alternatives?

thanks

Tim
 
V

Venkatesh

Every Component has a method called setCursor function. U an use that

To set a cursor to hourglass, u can say setCursor(Cursor.WAIT_CURSOR)

-Venkatesh
 
V

Vova Reznik

Is there a pattern for placing hourglasses on and off through GUI apps?

My actions are not necessarily near the code that created the button

someButton.addListener(actionListener);

I suppose I have to toggle the hour glass withing the action listener,
being careful to catch exceptions and turn it off?

Any alternatives?

thanks

Tim

First about one response
Venkatesh said:
Every Component has a method called setCursor function. U an use that

To set a cursor to hourglass, u can say setCursor(Cursor.WAIT_CURSOR)

-Venkatesh
What is he talking about?
Cursor.WAIT_CURSOR is int
Component doesnt' have method setCursor(int)
but it has method setCursor(Cursor).



Here isn't any standards.
If you need just show that program
is busy processing request it may look like

// --- set specific cursor ---
setCursor(?);
try{
// --- process
} catch(Exception ifYouWantOrNeed){
} finally{
// --- set default or previous cursor
setCursor(?);
}

in any actionPerformed and/or another event processing
methods.

You may want to read doc about
java.awt.Component#protected void processEvent(AWTEvent e)
or
java.awt.EventQueue#protected void dispatchEvent(AWTEvent e)



Also read about the Glass Pane
http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html

Personally I prefer to cover (set Visible) my RootPaneContainer with
glass pane that have wait cursor set as default
if task can be long (also read about multi threading in Swing)
 
C

Chris Lamb

First about one response

What is he talking about?
Cursor.WAIT_CURSOR is int
Component doesnt' have method setCursor(int)
but it has method setCursor(Cursor).

It is deprecated but there used to be/still is setCursor(int)

new style would be:

setCursor(new Cursor(Cursor.WAIT_CURSOR));

I think it was 1.2 and after that it was deprecated. It was in the Frame
class.

Chris
 
V

Venkatesh

Hi,

Sorry, the setCursor that I said is depricated. It is the setCursor
function in the Frame class.

The correct style now is:
setCursor(new Cursor(Cursor.WAIT_CURSOR));
 
V

Vova Reznik

Venkatesh said:
Hi,

Sorry, the setCursor that I said is depricated. It is the setCursor
function in the Frame class.

The correct style now is:
setCursor(new Cursor(Cursor.WAIT_CURSOR));

Correct way is:
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 

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

Forum statistics

Threads
474,261
Messages
2,571,040
Members
48,769
Latest member
Clifft

Latest Threads

Top