JprogressBar repaint problem!

Posted on 2003-02-20
Medium Priority
Last Modified: 2008-02-01
Hi everyone,
I want to create an task status indicator with JProgressBar.
I made one extended JDialog classs with a JProgressBar in it and when my
task starts I show this Dialog and tell the JPorgressBar to change it's
value to the desired one.
Everything seemed to be OK, but the dialog show's up when my task is
finished and it does't make sence ;)
(The task is creating a big HTML file from known amount of data)
So I am not very aquainted with Threads  but I think that the answer is
somewhere there.
Can anyone help me find the answer?
Thanks in advance.
Question by:sebastiano
LVL 14

Accepted Solution

Tommy Braas earned 200 total points
ID: 7988011
Did you thread the dialog? What you want to do, is to thread the time consuming/blocking task.

Create a thread for handling the creation of the HTML file;
public class HTMLBuilder implements Runnable
   // the class that does the work right now
   YourWorkClass workerBee;

   public HTMLBuilder(YourWorkClass workerBee)
      this.workerBee = workerBee;

   public void run()
      // do the work of creating HTML in here

HTMLBuilder htmlBuilder = new HTMLBuilder();
Thread htmlThread = new Thread(htmlBuilder);

// create a new dialog
// make sure that the worker class knows how to send updates of its progress
YourProgressDialog yourProgressDialog = new YourProgressDialog();

What will happen now, is that the dialog will show WHILE the work is being done. All you have to make sure after this is that the class doing the work needs to be able to update the progress bar in regular intervals.

I hope this helps!

Assisted Solution

by:Mark Roberts
Mark Roberts earned 200 total points
ID: 7988016
It sounds as though you are performing the build of your HTML within your ActionListener for a component.  You will need to create a thread to perform the actual function rather than doing it directly in your ActionListener.  The event thread will only process one event at a time so as you are processing your HTML you are blocking the remaining events.

For examples of threaded swing programs see:


Expert Comment

ID: 9059205
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Expert Comment

ID: 9553726
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
SPLIT between orangeHead911 and MARoberts.  Both are possible solutions given 1 minute apart, without any comments from the questioner I can not decide if any one answer worked better for you.

Please leave any comments here within the next seven days.


Thomas Boshell
EE Cleanup Volunteer

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question