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

  • SEARCH
  • Home
  • 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 8892349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:58:37+00:00 2026-06-14T22:58:37+00:00

I’ve read many different articles about JProgressBar…including the dodgy code found over at Java;

  • 0

I’ve read many different articles about JProgressBar…including the dodgy code found over at Java; here.

Most indicate you need a SwingWorker to get things happening properly, which makes perfect sense, I understand that much. I am finding that when I call setProgress(value) to update the progressbar, it’s not triggering the propertyChange event most of the time. I’ve checked the value I’m passing to setProgess and it definitely changes every time, so I’m not sure if it’s just firing the event too quickly? Please see relevant code below, any help/explanation would be greatly appreciated.

class ProgBar extends SwingWorker
{
    public ProgBar()
    {
        addPropertyChangeListener(new PropertyChangeListener()
        {
           @Override
           public void propertyChange(PropertyChangeEvent evt)
           {
               if ("progress".equals(evt.getPropertyName()))
               {
                   int value = (Integer)evt.getNewValue();
                   System.out.println("propertyChange called with: " + value);
                   loginProg.setValue(value);
               }
           }
        });

        loginProg.setStringPainted(true);
        loginProg.setValue(0);
        setProgress(0);
    }

    @Override
    public Void doInBackground() throws InterruptedException
    {
        ...
        int count = 0;
        for (Folder f : folders)
        {
            ... // process 'f'
            setProgress((int)Math.min(((double)count/folders.length)*100.0, 100.0));
        }
        ...
        return null;
    }

    @Override
    public void done()
    {
        System.out.println("Done called.");
        setProgress(100);
        loginProg.setValue(100);
    }
}

JProgressBar called with this;

private void jButtonActionPerformed(java.awt.event.ActionEvent evt) 
{                                             
        // Create new thread to run progess bar.
        // Otherwise won't be able to update progress bar.
        ProgBar pb = new ProgBar();
        pb.execute();
    }
}    

EDIT:
Yeah, so I should have read the Javadocs better;

Because PropertyChangeListeners are notified asynchronously on the Event Dispatch Thread multiple invocations to the setProgress method might occur before any PropertyChangeListeners are invoked. For performance purposes all these invocations are coalesced into one invocation with the last invocation argument only.

For example, the following invokations:
setProgress(1);
setProgress(2);
setProgress(3);

might result in a single PropertyChangeListener notification with the value 3.

I.E. my assumption that setProgress was firing too quickly was correct. A ProgressMonitor might be a better solution.

  • 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-06-14T22:58:38+00:00Added an answer on June 14, 2026 at 10:58 pm

    Yeah, so I should have read the Javadocs better;

    Because PropertyChangeListeners are notified asynchronously on the Event Dispatch Thread multiple invocations to the setProgress method might occur before any PropertyChangeListeners are invoked. For performance purposes all these invocations are coalesced into one invocation with the last invocation argument only.

    For example, the following invokations:
    setProgress(1);
    setProgress(2);
    setProgress(3);
    might result in a single PropertyChangeListener notification with the value 3.

    I.E. my assumption that setProgress was firing too quickly was correct. A ProgressMonitor might be a better solution. I’ve confirmed this with the SSCCE and my program, both are simply firing setProgress too quickly and as a result, only the last value passed to setProgress is being passed through to the PropertyChange event.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I've tracked down a weird MySQL problem to the two different ways I was
I don't have much knowledge about the IPv6 protocol, so sorry if the question

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.