Article View: aus.computers.java
Article #304Re: JProgress Bar
From: Kirk Turner
Date: Tue, 20 Feb 2001 11:38
Date: Tue, 20 Feb 2001 11:38
68 lines
3813 bytes
3813 bytes
I've only had limited experience with the JProgressBar but this is what
I had. If you are doing the processing in a separate class its a little
more difficult, but...
Basically, I think the progress bar indicator is by a % string rather
than a series of bar indicating its progress. At least this is how I've
used it. So basically what you need to do is pass the JProgressBar to
the method doing the processing (if its a different class, or is not a
global variable) and then do a calculation to determine the percentage
of files finished and do myJProgressBar.setString(value + "%"); and the
string will be displayed.
So in something I wrote I had something like this:
public DataSet readDataFile(String filename, JProgressBar pbrStatus) {
int fileSize;
// Insert processing to get the number of lines in a file -> fileSize
//...
int newP = 0, oldP = 0;
do {
// Insert reading file information
//...
newP = (int)(java.lang.Math.rint((float)fd.getLineNumber() /
(float)fileSize * 100));
if (newP > oldP) {
oldP = newP;
pbrStatus.setString(newP + "%");
}
} while (s != null);
In your case you could do that calculation before you start processing
the next file. I also had some information for displaying the what was
actually happened, and it would be similar to above with a JLabel just
setting the text to the name of the file that you were currently
processing.
Also there may be refresh problems with such a system so you may need to
do a repaint on the JFrame that the progress bar is in for it to be
visible. Perhaps someone knows whether a repaint works in the parent
frame if your in a modal dialog - I havent actually tried.
Hope that helps a little,
Kirk
Mario Dima wrote:
>
> I have an application that processes some files, and it I want a visual
> indication of the processing. What better than a JProgress bar. So I start
> by studying the documentation and all of the books that I have, as well as
> all my web resources, but nowehre can I com up with a stright forward
> example of how to use a JProgress bar. All I want is to give it the total
> number of files to be processed, and tell it to increment every time a file
> is finished, and perhaps a string diplaying the file name.
>
> All help is appreciated.
>
> TIA
> Mario
Technical Details
Message-ID:
<3A925729.E0A08295@wagoonline.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!130.133.1.3!fu-berlin.de!newsfeed.ozemail.com.au!ozemail.com.au!not-for-mailReferences:
<n7nV5.10645$IE2.568727@news1.sshe1.sk.home.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d6b,811890bd19610234 X-Google-Attributes: gid111d6b,public X-Google-Thread: 113ae9,811890bd19610234 X-Google-Attributes: gid113ae9,public X-Google-Thread: 10d6db,811890bd19610234 X-Google-Attributes: gid10d6db,public X-Google-Thread: 10a146,1a398f7cadb5834b,start X-Google-Attributes: gid10a146,public X-Google-Thread: 10fd6d,811890bd19610234 X-Google-Attributes: gid10fd6d,public X-Google-ArrivalTime: 2001-02-20 03:40:13 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!130.133.1.3!fu-berlin.de!newsfeed.ozemail.com.au!ozemail.com.au!not-for-mail Message-ID: <3A925729.E0A08295@wagoonline.com> From: Kirk Turner <kirk.turner@wagoonline.com> Organization: WA Go Online X-Mailer: Mozilla 4.74 [en] (X11; U; Linux 2.2.16 i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: aus.computers.java,comp.lang.java.gui,comp.lang.java.help,comp.lang.java.misc,comp.lang.java.programmer Subject: Re: JProgress Bar References: <n7nV5.10645$IE2.568727@news1.sshe1.sk.home.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 68 NNTP-Posting-Host: sa.techparkwa.org.au X-Trace: ozemail.com.au 982669208 203.103.99.146 (Tue, 20 Feb 2001 22:40:08 EST) NNTP-Posting-Date: Tue, 20 Feb 2001 22:40:08 EST Distribution: world Date: Tue, 20 Feb 2001 19:38:17 +0800