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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:42:10+00:00 2026-06-08T11:42:10+00:00

I need to change jlabel.text several times by one click button in swing. In

  • 0

I need to change jlabel.text several times by one click button in swing. In this code i need set label text to start before dowork() function and set to in progress in middle and set it to end after dowork() (status type in jlabel and dowork has long time execution) :

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 
        status.setText("start");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException ex) {
            Logger.getLogger(PelakInRFID.class.getName()).log(Level.SEVERE, null, ex);
        }
        status.setText("in progress");
        dowork();
       try {
            Thread.sleep(10000);
        } catch (InterruptedException ex) {
            Logger.getLogger(PelakInRFID.class.getName()).log(Level.SEVERE, null, ex);
        }
        status.setText("end");

 }

In this code status only set to end and start doesn’t show.

  • 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-08T11:42:12+00:00Added an answer on June 8, 2026 at 11:42 am

    I would try to use a SwingWorker instance (in particular its doInBackground method) to do what you are currently doing in doWork on a different thread than the main UI thread. The way it’s written, your listener method is bound to freeze the user interface during execution, which, as you said, can be a long time, resulting in a bad user experience.

    Change to JLabel text can happen in three different places: first, just before invoking execute on (i.e. starting) the SwingWorker; second, using the publish/process mechanism that SwingWorker makes available to publish intermediate results on the user interface; third, in the done method, which is called again on the UI thread as soon as the SwingWorker has finished the execution of its doInBackground method.

    References: Oracle’s tutorial on worker threads and SwingWorker, JavaDoc API documentation of the SwingWorker class.

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

Sidebar

Related Questions

I need change background of all text that have two spaces from the start
I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
I need to change the + to - when toggled. The code is set
I need change keyboard language. with this code i can change the language if
I need a little help with swing. This is my code: public class UIdostawca
I have database, and in one the tables I need change the values of
I need to change table name from lowercase to uppercase but using this statement
I need to change a menuStrip item text of the main window (mdi container)
I have a JScrollPane that holds a JLabel using the following code: //Create TEXT
I need change a value in a ini file like this val2 is the

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.