• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 75721
354
  • 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: 22650
126
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).
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic