aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Suggestions on making a progress bar/waiting message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Suggestions on making a progress bar/waiting message" Watch "Suggestions on making a progress bar/waiting message" New topic
Author

Suggestions on making a progress bar/waiting message

Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

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


Olly
Rudolf Meerkotter
Greenhorn

Joined: Apr 03, 2008
Posts: 14
A progress bar would make sense


SCJP 5, SCWCD 5, SCBCD 5
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

In which case you should definitely check out javax.swing.SwingWorker


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

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

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18140
    
    8

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

Joined: Jun 09, 2003
Posts: 4632
ProgressBar tutorial

http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Suggestions on making a progress bar/waiting message
 
Similar Threads
How to get length of task for JProgressbar?
Set an Normal Inner class variable without creating an instance of the class
JProgressBar with a database connection
Adding progressbar
Learning to use JProgressBar, having some problems. Need some help here.