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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:53:28+00:00 2026-05-12T13:53:28+00:00

I have a UI built inside a JFrame. One of the buttons starts a

  • 0

I have a UI built inside a JFrame. One of the buttons starts a long running call (still within the same java process), and during it’s execution, the UI is frozen.

I figured, to make it clear that things are still running, I can display a progress bar, perhaps in a popup, so that the user can be kept up-to-date as to what the program is doing.

So I’m creating a new JDialog, adding a JProgressBar to it, and updating it as things happen. The problem is that that dialog’s content isn’t getting updated. Changes I make to it’s title show up immediately, and anything I output to the console, but nothing in the UI itself.

Is there a command I can issue to force a repaint?

Here’s the core of this section:

  killWindow = new JDialog();
  killWindow.setUndecorated(true);
  killWindow.setTitle("stopping tests - 0 of " + numActive);
  killProgress = new JProgressBar(0, numActive);
  killWindow.add(killProgress);
  killProgress.setStringPainted(true);
  killWindow.pack();
  killWindow.setLocationRelativeTo(frame);
  killWindow.setVisible(true);

Then, as we progress…:

  killProgress.setValue(++killedTests);                    // not seen!
  killProgress.setString("Killing test on " + nickname()); // not seen!
  log("Killed another test, " + killedTests + " so far");  // visible in real time
  killWindow.setTitle("stopping tests - " + killedTests +
                      " of " + killProgress.getMaximum()); // visible in real time

What am I missing? I tried googling and searching here on SO, and haven’t really seen anything obvious?

  • 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-12T13:53:28+00:00Added an answer on May 12, 2026 at 1:53 pm

    You have to perform your long running task in another thread.

    There is this thread called “AWT Event Dispatch Thread” which is in charge of the update of UI components. If it is busy performing your long running task it won’t update the UI ( nor refresh you dialog ).

    You may consider using SwingUtilities or a SwingWorker.

    From the SwingWorker documentation here’s a sample

    final JLabel label;
    class MeaningOfLifeFinder extends SwingWorker<String, Object> {
       @Override
       public String doInBackground() {
           return findTheMeaningOfLife();
       }
    
       @Override
       protected void done() {
           try { 
               label.setText(get());
           } catch (Exception ignore) {
           }
       }
    }
    
    (new MeaningOfLifeFinder()).execute();
    

    By running your long task in a different thread, you’re allowing the AWT event dispatch thread to show a responsive UI.

    You may take a look at this “Lesson from the Java tutorial” to understand better these concepts.

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

Sidebar

Related Questions

I have built a table which is basically done by HorizontalScrollView inside a ScrollView
i've built a BaseAdapter extended class for my list view.. inside i have a
I have built a very simple internal messaging system inside my application, i want
I have a dynamic object built inside IronPython and I would like to build
I have built a web form with some tables and custom controls inside it,
One of my UIViewController has several child view controllers. They are built inside the
I have built a simple interface that fills my entire JFrame. I am using
I wanted to have a discussion on Java GUIs, right now, I'm still in
I have built a stateless java servlet web application and the requirement is to
Inside a MATLAB function I have built a matrix A, whose dimensions M and

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.