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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:22:24+00:00 2026-05-27T00:22:24+00:00

public void myMethod { MyProgessBarFrame progFrame = new MyProgressBarFrame(); // this is a JFrame

  • 0
public void myMethod {
   MyProgessBarFrame progFrame = new MyProgressBarFrame(); // this is a JFrame
   progFrame.setVisible(true); // show my JFrame loading

   // do some processing here while the progress bar is running
   // .....

   progFrame.setvisible(false); // hide my progress bar JFrame
} // end method myMethod

I have the code above. But when I run it, the do some processing section does not process until I close the progress bar JFrame.

How will I show my progress bar and tell Java to continue in the do processing section?

  • 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-27T00:22:24+00:00Added an answer on May 27, 2026 at 12:22 am

    You’ve got a classic problem with concurrency and Swing. Your problem is that you’re doing a long-running task on the main Swing thread, the EDT or Event Dispatch Thread, and this will lock the thread until the process is complete, preventing it from doing its tasks including interacting with the user and drawing GUI graphics.

    The solution is to do the long-running task in a background thread such as that given by a SwingWorker object. Then you can update the progressbar (if determinant) via the SwingWorker’s publish/process pair. For more on this, please read this article on Concurrency in Swing.

    e.g.,

    public void myMethod() {
      final MyProgessBarFrame progFrame = new MyProgessBarFrame();
      new SwingWorker<Void, Void>() {
         protected Void doInBackground() throws Exception {
    
            // do some processing here while the progress bar is running
            // .....
            return null;
         };
    
         // this is called when the SwingWorker's doInBackground finishes
         protected void done() {
            progFrame.setVisible(false); // hide my progress bar JFrame
         };
      }.execute();
      progFrame.setVisible(true);
    }
    

    Also, if this is being displayed from another Swing component, then you should probably show a modal JDialog not a JFrame. This is why I called setVisible(true) on the window after the SwingWorker code — so that if it is a modal dialog, it won’t prevent the SwingWorker from being executed.

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

Sidebar

Related Questions

I have a method that contains an asynchronous call like this: public void MyMethod()
In my code I have often situations like this: public void MyMethod(string data) {
I have the following code: public void myMethod(Object... args) { System.out.println(this is myMethod); }
I have a generic method defined like this: public void MyMethod<T>(T myArgument) The first
I have some code like this: public void someMethod (Object x) { if (x
public class D { void myMethod() { try { throw new IllegalArgumentException(); } catch
Given this class: public class MyClass { private void MyMethod() { //... } public
If I have a method such as: public void MyMethod(int arg1, string arg2) How
public class MyClass { public int Age; public int ID; } public void MyMethod()
MyClass.java: package test; public class MyClass { public void myMethod(){ System.out.println(My Method Called); }

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.