This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to display time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to display time" Watch "How to display time" New topic
Author

How to display time

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi,
I am able to get the current system time on a JLabel but I want to see the time changing on it please any body help me
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42956
    
  73
I'd probably start a thread that sleeps for whatever interval you want to update the label. Upon waking up it would set the text on the label with the current time before once again going to sleep.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20049
    
  30

javax.swing.Timer would be a perfect candidate. Its events are executed on the Event Dispatcher Thread so no need to work with invokeLater.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to display time
 
jQuery in Action, 3rd edition