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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:28:06+00:00 2026-06-18T08:28:06+00:00

Ok, this is my problem: I am trying to build a custom download helper

  • 0

Ok, this is my problem:

I am trying to build a custom download helper for one of my projects. I wanted my implementation to allow multiple downloads (running simultaneously) so I figured that I should start a thread for every download.

However, the problem is that I also want to update the GUI of my program. To do that, I wanted to use the invokeLater() method since Swing is not thread-safe.

Now: If I use the invokeLater() method inside each thread to update a progressbar, how would a thread know about my GUI? Please let my know what you think about this approach and how you would solve this problem.

Please consider this aswell:

public class frame extends JFrame {
    public frame() {
        //the constructor sets up the JProgressBar and creates a thread object
    }

    public void getFiles() {
        // Here I would start the thread.
        thread.start();
    }
}

And here is another class that sets up the thread:

public class theThread extends Thread {
    // Here I would create the thread with its constructor 

    public void run() {
        // Here comes some code for the file download process
        //
        // While the thread is running the method below gets called.
        updateGUI();
    }

    public void updateGUI() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                // Here I need to place the code to update the GUI
                // However, this method has no idea of what the GUI looks like
                // since the GUI was setup in the class 'frame'.
            }
        });
    } 
}    
  • 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-18T08:28:07+00:00Added an answer on June 18, 2026 at 8:28 am

    You could have a constructor that takes the frame as a parameter:

    public class TheThread extends Thread {
        private final JFrame frame;
    
        public TheThread(Runnable r, JFrame frame) {
            super(r);
            this.frame = frame;
        }
    }
    

    Now you can call frame.doSomething(); from your updateGUI method.

    Note that it is generally better practice to implement Runnable than to extend Thread.

    Alternatively, you could use SwingWorkers which have been designed to handle situations like what you describe (background thread that updates the UI).

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

Sidebar

Related Questions

I'm having this problem. I'm trying to build an UITableView with data from a
I'm running into this problem when trying to call a SOAP Web Service from
I've encountered this problem (while trying to add SQL Server Database (.mdf) file to
I have this problem when trying to run hello world program using android SDK.
I came across this problem when trying to decode json into an array ,
Ok I have this problem I'm trying to use Jquery to load a partial
I have been having this annoying problem when trying to implement a picture gallery
Would love some opinions on this problem I'm trying to workout. I'm trying to
I am trying to solve this problem http://www.spoj.pl/problems/PEBBMOV/ . I think I have the
I'm trying to debug this problem but not sure where exactly i need to

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.