Win a copy of Murach's MySQL this week in the JDBC and Relational Databases 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Suggestions on making a progress bar/waiting message

 
Ranch Hand
Posts: 176
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys

I've got this program which saves data into TXT files and it takes very long to do so. The problem is not how long it take though, the more annoying problem is that everything in my program is blocked until it's done saving and doesn't notif the user of what's going on.... What I mean is I want a message (i was thinking a little window) to appear where saying "Saving..." and disappearing when the program is done saving.

Which SWING class would the best to do this? I was thinking of using JOptionPane but those windows come with buttons... which is unnecessary

Must I create an extension of the JFrame class or is there an alternative?

Any suggestion will be much appreciated

Thank-you

P.S. I was also thinking of adding a progress bar and I could
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A progress bar would make sense
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> the more annoying problem is that everything in my program is blocked until it's done saving and doesn't notif the user of what's going on....

if you're doing this via actionPerformed() or similar listener, you're probably blocking the swing thread (EDT),
in which case it would be better to save the data via a separate thread, thus leaving your GUI 'responsive',
then perhaps you wouldn't need a progress bar, as the data would be being saved in the background
 
Sheriff
Posts: 22778
130
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
In which case you should definitely check out javax.swing.SwingWorker
 
Olivier Legat
Ranch Hand
Posts: 176
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh there's a class called JProgressBar... logically that's what I'm looking for.

I've checked out the SwingWorker class but we're not allowed to use this since it's part of Java 6 (and this project is meant to be coded in Java 5). What is the best alternative?

So far my efforts reveal a problem which seems to be what Michael Dunn pointed out:

I have an algorithm that looks somewhat like this:The problem with this is that the bar doesn't move as the data is being saved. Instead it just magically goes from 0 to 100 when the process is done (which through my understanding seems to be a Thread problem is everything else works when I test it on its own). So to try get around this problem I changed my algorithm a bit to something like:But I still get a similar problem....

I pressume I need to take my first algorithm and run it on a separate Thread but I don't understand why my second algorithm doesn't work :S could anyone please explain this.

Thank-you

 
Marshal
Posts: 28123
94
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty sure that SwingWorker was a class that appeared in tutorials and web articles going back several years, and it was only inducted into Java recently. So if you could track down one of those articles you could get the code for it and use it in your project (legalisms permitting, of course).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ProgressBar tutorial

http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
 
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic