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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:07:45+00:00 2026-05-25T10:07:45+00:00

I have a GUI in which some groups of JComponents get batch-updated, i.e., I

  • 0

I have a GUI in which some groups of JComponents get “batch-updated”, i.e., I have a loop and for almost every iteration of the loop, I need to update these JComponents. So, I tried to do the updates alongside the computations in the loop but it didn’t go well being that, (if I interpret correctly) the updates were “slowed down” by the computations, the effect being only the last update became perceptible to the user.

That’s when I thought of putting all update-related code on a separate thread. First off, I created an interface called UpdatableComponent which will wrap all JComponents that must be updated:

public interface UpdatableComponent {
/**
 * Implementors should be the one responsible for typecasting update
 * into the appropriate objects.
 */
public void update(Object update);
}

So if, for instance, I want to update a JLabel

public class UpdatableJLabel implements UpdatableComponent{
    private JLabel l;

    public UpdatableJLabel(JLabel l){
        this.l = l;
    }

    public void update(Object update){
         l.setText((String) update);
    }
}

Then, my Runnable class for threading:

public class UIUpdateRunnable implements Runnable {

private UpdatableComponent[] forUpdating;

public UIUpdateRunnable(UpdatableComponent[] uc) {
    forUpdating = uc;
}

public void run() {
    int limit = forUpdating.length;

    for(int i = 0; i < limit; i++){

    }
}

}

And this is where I hit a snag. How do I know what argument to pass for each UpdatableComponent’s update method? I thought of maintaining an Object array, arguments, which will map an UpdatableComponent to an argument for its update method (I have a setter method for it, of course). But then that would be (1) too tightly-coupled—bad design!—and (2) too much for a thread; the loop inside run will continuously call update on each UpdatableComponent, giving it its designated argument, updating regardless whether it actually updated or not.

I can’t help but feel that I may have missed a simple way to do it. Any suggestion/advice will be very welcome. Thank you.

  • 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-25T10:07:46+00:00Added an answer on May 25, 2026 at 10:07 am

    It sound like a SwingWorker is what you are looking for. The computation is done inside the method doInBackground(), results are publish()ed and process() then updates the components.

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

Sidebar

Related Questions

I have a win32 GUI (MFC) application which I need to port to a
I have written a GUI application which after performing some analyses on a large
I have a Flex GUI which is using AMF Streaming to BlazeDS on WebLogic
I have 2 projects. One project is a core and contains the GUI which
I have a GUI app written in C++/CLI which has a load of configurable
I have designed this gui in netBeans which has a canvas , a couple
i have this GUI screen shots from the design team which i needs to
I have a GUI program, which would call a cmd in this GUI program.
I have a class (simulation) which creates an instance of another class (GUI). Inside
I have an application which displays properties dialogs for various GUI-accessible objects. Because there

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.