Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Jay Crawf
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:
 
Paul Clapham
Sheriff
Posts: 22185
38
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.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and, Welcome to the Ranch!
 
Randall Twede
Ranch Hand
Posts: 4583
6
Java Python 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).
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!