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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:47:55+00:00 2026-06-06T21:47:55+00:00

I have a modal dialog containing a JLabel. This dialog calls a method in

  • 0

I have a modal dialog containing a JLabel. This dialog calls a method in another class which does a long-running lookup activity. I’d like this lookup class to update the JLabel, which is passed from the modal dialog.

I’ve tried updating the JLabel from the code loop in the lookup process, and from within a Timer. (I found that the actionPerformed method of a Swing timer never gets called when a modal dialog is running.) Since implementing the Timer, I moved my lookup process to a separate Thread.

My lookup works, but the JLabel is still never repainted until the end of the process. I’ll be grateful for any help.

Here’s the relevant method. The DictionaryTuple is a POJO containing two fields: a List and a String. Just getters and setters, but dictionaryThread does have access to tupleList; note that we don’t touch it here until dictionaryThread is finished.

public List<DictionaryTuple> findTuples() {
    tupleList = new ArrayList<DictionaryTuple>();
    Thread dictionaryThread = new Thread(this);  // This is the long-running lookup thread
    dictionaryThread.start();

    progressTimer = new Timer();
    progressTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
                       //  progressCaption is updated in dictionaryThread
            synchronized (progressCaption) {
                lblProgress.setText(progressCaption);
            }
            lblProgress.repaint();
            Thread.yield();
        }
    }, 250, 250);

     try {
        dictionaryThread.join();
    } catch (InterruptedException e) {
    } finally {
      progressTimer.cancel();
      lblProgress.setText("");
      progressCaption = "";
    }
    return tupleList;
}

I’ve also tried this variation; in that case, the inner run() invocations are held until the processing is completed:

    progressTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            synchronized (progressCaption) {
            System.out.println("Fire!");
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    System.out.println("Update");
                    lblProgress.setText(progressCaption);
                    lblProgress.repaint();
                }});
            }
        }
    }, 250, 250);
  • 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-06T21:47:56+00:00Added an answer on June 6, 2026 at 9:47 pm

    You need to show us exactly where you set the dialog to visible — is it before or after you call the findTuples() method? This is critical.

    Suggestions:

    • Always update the JLabel on the Swing event thread or EDT (event dispatch thread).
    • Don’t use a java.util.Timer to update the components of a Swing app.
    • You can use a javax.swing.Timer to update Swing components, but that’s not going to work here, unless you are using it to poll the background process.
    • Consider using a SwingWorker for your background threading and then update the JLabel via eitherthe publish/process methods of the worker or via a PropertyChangeListener added to the SwingWorker.
    • Call all your methods that you want running when the dialog is running before setting the dialog to visible.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a modal dialog box which is containing search field. when I select
I have a modal settings dialog which is a JDialog. In this settings window
I have a modal dialog in main page, then I add jPlayer to this
I have a modal dialog which opens on click of Edit button of my
When I have only one modal dialog It works in Safari too. In this
I have a modal dialog which contain form and hidden iframe to which form
I have a modal dialog class that I am extending in order to show
I have a button which launches a modal dialog - it just creates a
I have a modal dialog which has a form. When a user clicks the
I have a modal form that is pretty much same as this one: http://jqueryui.com/demos/dialog/modal-form.html

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.