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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:54:41+00:00 2026-05-27T11:54:41+00:00

I am quite new to Java so I am sorry for this beginner question.

  • 0

I am quite new to Java so I am sorry for this beginner question.

I have a JButton, when I click on it, there are a few MySQL queries triggered and some updates in the display that take 2 or 3 seconds. During this time my user interface freezes completely. Is there a way to avoid that ?
Maybe I should use something like synchronized, thread or runnable but I don’t understand very well.
Could somebody explain me please ?

Thank you very much.

Regards.

Vincent

  • 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-27T11:54:41+00:00Added an answer on May 27, 2026 at 11:54 am

    Because you are executing the queries on the same thread as the user interface, that thread is unable to receive any user commands in the meantime, thus it “freezes”.

    The solution is to start a new thread and execute the queries in parallel and then use something like SwingUtilities.invokeLater to update the ui. Something like:

     // button action listener code
    
     Thread t = new Thread(new Runnable() {
        public void run() {
    
           // execute query here
    
           SwingUtilities.invokeLater(new Runnable() {
               public void run() {
    
                   // update the ui here
    
               }
           });
        }
     });
     t.start();
    

    SwingUtilities.invokeLater effectively queues the update action until all pending events on the UI thread have been processed. Read the javadoc here.

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

Sidebar

Related Questions

Sorry, I'm new to Java and there's probably a very simple answer to this.
Sorry, I'm quite new to Java. I've stumbled across HttpGet and HttpPost which seem
I'm quite new to Java Programming and am writing my first desktop app, this
I'm quite new to Java and have come accross to a strange behaviour that
Im quite new to Java and i have stumbled upon the following problem. Im
I'm quite new to java OOP concept. I have some problems in implementing some
First of all, I have to say I'm quite new to Java. I need
I'm quite new to Java and am stuck with this, please. Well I know
I'm quite new in C++ after few years in Java and eclipse, I got
I'm beginning to work with Eclipse for some Java development. I'm quite new to

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.