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 8465013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:55:18+00:00 2026-06-10T14:55:18+00:00

I seem to have a problem with SwingWorker. I basically implemented the Java Example

  • 0

I seem to have a problem with SwingWorker.
I basically implemented the Java Example Code updating the UI from the propertyChange() method of my JFrame.

I also copied the sleep up to one second part in doInBackground.
This leaves me with a good update rate of setProgress within my Worker.

However the propertyChange Event is fired only once about every 10sec.
I know from the API that not every setProgress fires an event, and I’m ok with that, however it seems that this is kinda slow and too many events are lost.

When stepping through in a Debugger I get a better rate, ~once every 3 calls to setProgress

Any ideas why it is so slow?

Here are the parts of my Code:

public Void doInBackground() {
    Random random = new Random();
    setProgress(0);
    float getSize=0,gotSize=0;
    while (Sync.syncing) {
        //Sleep for up to one second.
        try {
             Thread.sleep(random.nextInt(1000));
        } catch (InterruptedException ignore) {
            ignore.printStackTrace();
        }
        try{
            getSize=Main.getSyncGet();
            gotSize=Main.getSyncGot();
            System.out.println("setProgress: "+(gotSize/getSize));
            setProgress((int)((gotSize/(getSize))*100));
        }catch(Exception e){
            Main.LOGGER.log(Level.WARNING,"Error setting progress",e);
        }
    }
    return null;
}

public void propertyChange(PropertyChangeEvent evt) {
        if ("progress" == evt.getPropertyName()) {
            jpb.setValue((Integer) evt.getNewValue());
        }
}

Kind Regards

Jens

  • 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-10T14:55:19+00:00Added an answer on June 10, 2026 at 2:55 pm

    Your problem is quite possibly here:

    System.out.println("setProgress: "+(gotSize/getSize));
    setProgress((int)((gotSize/(getSize))*100));
    

    Have you tested that the progress is actually being changed? A better println would be:

    int value = (int)((gotSize/(getSize))*100);
    System.out.println("setProgress: "+ value);
    setProgress(value);
    

    Now check to see if value is in fact changing.

    Ooops, this is definitely wrong:

    public void propertyChange(PropertyChangeEvent evt) {
            if ("progress" == evt.getPropertyName()) {
                jpb.setValue((Integer) evt.getNewValue());
            }
    }
    

    Don’t compare Strings using ==. Use the equals(...) or the equalsIgnoreCase(...) method instead. Understand that == checks if the two objects are the same which is not what you’re interested in. The methods on the other hand check if the two Strings have the same characters in the same order, and that’s what matters here. So instead of

    if (fu == "bar") {
      // do something
    }
    

    do,

    if ("bar".equals(fu)) {
      // do something
    }
    

    or,

    if ("bar".equalsIgnoreCase(fu)) {
      // do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have a problem passing some strings on from one form to
I have a problem with my cfml code. The ListAppend() function doesn't seem to
Seem to have a problem starting my Java app: Exception in thread main java.lang.NoClassDefFoundError:
I seem to have stumbled over a problem regarding saving an xml file from
I seem to have a problem with this SQL query: SELECT * FROM appts
I seem to have a problem with the footer on my website. Basically its
I seem to have a problem with a Java batch insert. What it does
I seem to have a problem with getting MVC to fill in my custom
I seem to have a problem understanding how to conditionally test a boolean value
I seem to have a tricky problem since the latest ADT update to release

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.