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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:52:51+00:00 2026-06-01T15:52:51+00:00

I have a save button in a JFrame ;on clicking save the ‘save’ text

  • 0

I have a save button in a JFrame ;on clicking save the ‘save’ text sets to ‘saving….’; I need to set that text as ‘saved’ after a delay of 10 seconds.How is it possible in java?
Please help…

try {
    Thread.sleep(4000);
} catch (InterruptedException e) {

    e.printStackTrace();
}

This is what i did…but this wont shows as ‘saving’ during that delayed time.

  • 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-01T15:52:53+00:00Added an answer on June 1, 2026 at 3:52 pm

    If you want to provide the user with visual feedback that something is going on (and maybe give some hint about the progress) then go for JProgressBar and SwingWorker (more details).

    If on the other hand you want to have a situation, when user clicks the button and the task is supposed to run in the background (while the user does other things), then I would use the following approach:

    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {                                          
            button.setEnabled(false); // change text if you want
            new SwingWorker<Void, Void>() {
                @Override
                protected Void doInBackground() throws Exception {
                    // Do the calculations
                    // Wait if you want
                    Thread.sleep(1000);
                    // Dont touch the UI
                    return null;
                }
                @Override
                protected void done() {
                    try {
                        get();
                    } catch (Exception ignore) {
                    } finally {
                        button.setEnabled(true); // restore the text if needed
                    }
                }                    
            }.execute();
        }
    });
    

    Finally, the initial solution that was using the Swing specific timer:

    final JButton button = new JButton("Save");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {                                          
            // Take somehow care of multiple clicks
            button.setText("Saving...");
            final Timer t = new Timer(10000, new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent evt) {
                    button.setText("Saved");
                }
            });
            t.setRepeats(false);
            t.start();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application without a save button; saving happens automatically in the background.
I currently have a simple form that when you click the save button will
I have a bunch of text boxes and a save button to update something.
I have a button like that : <a href=@Url.Action(Create, City) class=save button><span class=icon-save></span>Save</a> Than
I have a save button so when users click, it will do a saving
How to remove Default Enter Click from page. that is Have one save button
I'm using ASP.NET and I have a save button on webform. When that save
I have two buttons for my form - a Save changes button and a
In my application I have a button to save some information. However, I would
I have a component mxml in which i have a save button, on click

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.