Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to update the contents displayed on a jFrame periodically  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, I've been lurking around for awhile, I've created an account in frustration with trying to solve this problem.

I want to refresh the contents of a jFrame periodically after it is initially displayed by the user with a button click. The frame has a jFreeChart on it based on data read in from a file, and I want it to redraw the chart regularly showing any new data written to this input file.

I tried putting in a loop with a delay around the whole draw function and having the chart re-display that way, but the frame just turns black while the loop is running and never really updates...

I also tried branching out the re display to another thread, but this has likewise failed to do what I thought it would.

How might I be able to get the frame to update its display at some interval, while using any new data that may have been added to the input file?

code to display chart:


Code to read in from file:
 
Sheriff
Posts: 23868
50
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use a Swing timer to do that. Here's a link to the tutorial: How to Use Swing Timers.
 
Bartender
Posts: 1104
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and, Welcome to the Ranch!
 
Ranch Hand
Posts: 4702
9
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul beat me to the answer by approximately 24 hours

on the other hand, it is a kind of unusual thing to do. usually we rely on Action Events(or some kind of event anyway).
 
Marshal
Posts: 61727
193
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't a Swing Timer fire action events? Look in the Java Tutorials.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!