• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Repainting JPanel

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I just started learning Swing.I'm trying to write a program in which there will be 2 panels.Panel1->for stopwatch Panel2->which will be displaying some data and it contains a button.

My concern is I'm using Threading to update the timer of stopwatch every second. After putting print statement i can see the stop watch part is running fine but the stopwatch panel is not getting updated every second.

Below is the some portion of my code relevant to this problem.

Can anybody help me out plzzzzzzzz!!!

PanelTop is the Class for stopwatch panel

Please let me know if my approach should be something else so as to achieve the requirement
Thanks in advance
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are using one thread to start the StopWatch, and you are querying it in another thread. It is worthwhile checking the interval between successive queries, because I think those intervals are too short for repainting.

If you have just started learning Swing, you might do well to try simpler examples. And remember that Swing components are not thread-safe.
 
Bhakta Pradhan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I solved this , actually I was not updating the timer label inside run method of PanelTop.java


Hi Campbell,

Thanks for spending some time to look into this problem.

Actually the Stopwatch code goes below ,I don't think it could be a problem in this scenario. What you say???


 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to respect Swing's single threaded rule.
http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html
http://download.oracle.com/javase/tutorial/uiswing/concurrency/index.html
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you take a look at javax.swing.Timer (for use within GUIs) and java.util.Timer (for anywhere else).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic