• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Can timer Update swing Widgets , or some tips needed.

 
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post.
Here is the problem :
I have a timer , and i want it to update my jlabel in a count Down manner ,
so the folowing code showd do this job ?
I write them in a button event , but it just run one time and never my jlable text reaches more than 1 .




Any help is appropriated.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You are scheduling the task for one execution only. There is another method which takes an argument which is the period (if you want repeated executions):
schedule(TimerTask task, long delay, long period)

Kaj
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now you've gotten the wait and incrementing i off the AWT thread into the timer thread which is a good thing. It's probably not a good thing for the timer thread to update the label text, though. I've done this and had all kinds of weird user experience problems ... fields would only update if you resized the window and such.

The trick is to put the update into yet another runnable on the AWT thread. Look up the doc on SwingUtilities.invokeLater() and holler if you need help.
reply
    Bookmark Topic Watch Topic
  • New Topic