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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:49:48+00:00 2026-05-22T14:49:48+00:00

I have problem with refreshing swing components inside Mouse action event handler. Problem is

  • 0

I have problem with refreshing swing components inside Mouse action event handler. Problem is that all jLabels which are changed in this function that their changes are visible after jButton1MouseClicked() is done. Here is my function:

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      

    int cycles = Integer.parseInt(c.settings.get("cycles"));
    statusMessageLabel.setText("Data collection in progress...");

    for(int i=1;i <= Integer.parseInt(c.settings.get("cycles"));i++) {

        jLabelCycle.setText(Integer.toString(i));

        //here are some functions which are implementing data collection


        if(i < cycles){
            int counter = Integer.parseInt(c.settings.get("interval"));
            while(counter >= 0){
                jLabelTimer.setText(Integer.toString(counter));
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(AppCView.class.getName()).log(Level.SEVERE, null, ex);
                }
                counter--;
            }
        }

    }
    statusMessageLabel.setText("Data collection has been finished.");
}    

Can you please help me ? I really need this changes to be visible immidiaetly because one jLabel visualize counting till next cycle and second one is visualizating actual cycle number. I tried call function repaint() on all jLabels after i changed them but it didnt help.

Thank you all for any help.

  • 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-22T14:49:49+00:00Added an answer on May 22, 2026 at 2:49 pm

    In AWT, much like most other GUI systems, all events including repaints are done on a single thread, the AWT Event Dispatch Thread (EDT). You are blocking that thread in the event listener, so the repaint events on the label cannot get through.

    I suggest rewriting your code to use use javax.swing.Timer instead of Thread.sleep.

    In general, long running operations should be handled on a separate thread. Any operations touching AWT or Swing components should be queued for running on the AWT EDT using java.awt.EventQueue.invokeLater.

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

Sidebar

Related Questions

Possible References I have found a similar problem: Refreshing a SQL database connection which
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with fancybox. I want to write a function that will run
i have problem with autorotate on iphone i set up in all classes -
I have got a problem here in terminating the threads. The problem is that
I have a semi-complicated problem and hoping that someone here will be able to
I have created a captcha which looks like this: <img src=/cgi-bin/rand.pl /> The problem
I have the following refreshing timer: <s:url id=getDeployQueue action=deploymentQueue > <s:param name=readonly value=readonly />
I have a problem with two separate transactions that are flushed to the database

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.