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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:51:18+00:00 2026-06-02T20:51:18+00:00

I have application with: one JTextField for user input, one JLabel fro showing busy

  • 0

I have application with:

  • one JTextField for user input,
  • one JLabel fro showing busy status,
  • one JTextArea for printing results of search.

I want user to write text to textfield, press enter and see results. I have listener like this:

private void searchForPattern(java.awt.event.ActionEvent evt) {
        textArea.setText("");
        busyLabel.setText("Searchnig ...");
        doSearch();
        busyLabel.setText("Idle");
    }

In doSearch there is quite complicated algorithm that opens lots of XML files and searches for given pattern, it takes a while. Text of busyLabel is changed to Searching … only after doSearch completed. There is no second thread in doSearch, only lot of IO operations.

How can I fix this?

  • 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-02T20:51:22+00:00Added an answer on June 2, 2026 at 8:51 pm

    You’ve got a classic Swing concurrency issue (tutorial: Concurrency in Swing) where doSearch is tying up the Swing event thread. Since this thread is where Swing does all of its painting/drawing and interacting with users, if it gets tied up by code that takes any perceptible amount of time to complete, the whole application “freezes” with no components getting updated and all user interactions getting ignored.

    Solution: do it on a background thread such as that provided by a SwingWorker object. Set the “Idle” String into the JLabel in the SwingWorker’s done() method.

    i.e.,

    private void searchForPattern(java.awt.event.ActionEvent evt) {
      textArea.setText("");
      busyLabel.setText("Searching ...");
      new SwingWorker<Void, Void>() {
         @Override
         protected Void doInBackground() throws Exception {
            doSearch();
            return null;
         }
    
         @Override
         protected void done() {
            busyLabel.setText("Idle");
         }
      }.execute();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one application which uses the standard .NET forms authentication cookie, now I
I have one application that prints messages from Test.exe in console .My java program
i have one application which is build using VB.NET now i required to add
I have an application with one form in it, and on the Load method
I have an application on one domain that displays content from another application from
The problem: we have one application that has a portion which is used by
I have zero experience writing applications with Swing, but I have one application with
I have developed one application which will have activities and one background service and
I have created one application in flex that is accessing the Java webservice using
I have created one application in j2me, I have used json parsing in that

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.