• 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:

How to update the contents displayed on a jFrame periodically

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28398
100
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and, Welcome to the Ranch!
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 80649
475
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't a Swing Timer fire action events? Look in the Java Tutorials.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic