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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 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