Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:12:15+00:00 2026-05-21T09:12:15+00:00

I have strange problem. I set a JProgressBar: private JProgressBar progressBar; public void foo()

  • 0

I have strange problem. I set a JProgressBar:

private JProgressBar progressBar;

public void foo()
{
    ...
    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    ...
    contentPane.add(progressBar);
    ...
}

But it changes only when I put setValue function it in some places in code, not everywhere:

public void foo2()
{
    progressBar.setValue(100); //working
    if(...)
    {
        System.out.println("These instructions are executing"); //working
        progressBar.setValue(0);                                //not working
    }                             
}

So, what am I doing wrong? Why the second instruction doesn’t work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:12:15+00:00Added an answer on May 21, 2026 at 9:12 am

    The value of the progress bar is really updated. But it isn’t simply on the screen yet. Often, we use progress bars in loops. But, while you are in the loop, which you probably invoked by clicking a button it isn’t painted. Why? Because you invoked it by clicking a button. When you click a button, all the code you’ve made for that button is being executed by the AWTEventThread. This is the same thread that keep track of all the Swing components, and checks wether they have to be repainted. That is the thread that makes your JFrame come alive. When you hover a button and the color changes a bit, it’s done by the AWTEventThread.

    So, while you are working in the loop, the AWTEventThread can’t update the screen anymore.

    This means there are two solutions:

    1. (Recommend) You should create a separate thread which executes the loop. This means the AWTEventThread can update the screen if necessary (when you call bar.setValue(...);)

      public void yourButtonClickMethod()
      {
          Runnable runner = new Runnable()
          {
              public void run() {
              //Your original code with the loop here.
              }
          };
          Thread t = new Thread(runner, "Code Executer");
          t.start();
      }
      
    2. Manually repaint the progress bar. I did it always with bar.repaint(); but I’m wondering if it will work. I though it was that method. If that doesn’t work, try: bar.update(bar.getGraphics());.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange problem with Eclipse Galileo. I set Java 1.6 as my
We have a strange problem. I added a couple of new schema's and orchestrations
This is a quite strange problem. I have set a setting variable in Application
Having a strange problem with a page set to 100% fluid width which has
i have a strange problem with truezip. i run the following code: TFile.setDefaultArchiveDetector(new TArchiveDetector(zip));
I have this strange problem in JQuery. I try to set a value to
i have a very strange problem with NSTableView in XCode 4.2. I've set the
I have a strange problem here, I want to create an emtpy trigger: SET
I have a very strange problem with #any? printing true for an array that
I have strange problem with sharepoint and ajax functionality. We have an UpdatePanel placed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.