Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Progress Bar

 
Jason Kretzer
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an executable jar that extracts files from itself. I would like to have a JProgressBar show the progress of this. Below is the code I use for extraction. How can I implement a JProgressBar to use this? I would like to increment it with each "buffered IO dump".

Thanks in advance,
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jason,
Probably the best way to do this is to construct a JProgressBar and a Timer (javax.swing.Timer). Then add an ActionListener to the Timer and in the actionPerformed method update the Progress Bar. You'll probably have to experiment with how often the Timer fires to get the granularity you want. As you probably know you shouldn't modify any swing components outside the event thread, so don't be tempted to just update the Progress bar on the fly.
One other possibility you may check out is the ProgressMonitor class.
Hope this helps
Michael Morris
SCJP2
[ March 25, 2002: Message edited by: Michael Morris ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic