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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:41:12+00:00 2026-05-26T13:41:12+00:00

I have a statusbar in a Swing application that continuously prints status. All objects

  • 0

I have a statusbar in a Swing application that continuously prints status. All objects and classes within the application will be using this setStatus method to paint the status bar

public def setStatus(statusText){       
        Thread.start {
             ljaStatusBarButton.setText("Status : $statusText . . . .")
             sleep(3000)
             ljaStatusBarButton.setText("Status : Waiting for user action . . . .")
                     interrupt() // or stop() ?  
        }
    }

The status bar will display the status for 3 sec and revert back to a status saying waiting for user action.

This does work correctly but my concern is that the above method will be call multiple times from the UI which also means a new Thread object will be created everytime a status is set. Keeping this is mind, I’ve explicitly added a interrupt() at the end as I want to indicate the compiler that I am not in need of this thread anymore. And also, how much can I bet on Java’s garbage collection to ensure that the stopped/interrupted threads will be cleaned up soon? Or is there a better workaround for this multiple thread objects issue?

  • 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-26T13:41:13+00:00Added an answer on May 26, 2026 at 1:41 pm

    Your code is incorrect as you are using Swing outside of the EDT

    As you are using groovy already, why not use the SwingBuilder helpers that were added to make this sort of thing easier?

    import groovy.swing.SwingBuilder
    
    ...
    
    public def setStatus( statusText ) {
      // If we are not already on the EDT, static SwingBuilder.build(Closure) will do that for us.
      // In the case of an event handler like the actionPerformed for the button, then naturally
      // we're on the EDT already and the building will continue immediately.
      SwingBuilder.build {
    
        // doOutside will run the following code in our own thread
        doOutside {
    
          // Then change the swing components back on the EDT
          edt {
            ljaStatusBarButton.text = "Status : $statusText . . . ."
          }
    
          // So this sleep is in our own thread again (from doOutside)
          sleep(3000)
    
          // Then change the swing components back on the EDT
          edt {
            ljaStatusBarButton.text = "Status : Waiting for user action . . . ."
          }
        }
      }
    }
    

    Taken in part from the MultiThreading with SwingBuilder example

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

Sidebar

Related Questions

I have an app that sets the statusbar color like this - (BOOL)application:(UIApplication *)application
I've got a small Cocoa problem. I have a StatusBar application that has an
I have a form with a statusbar that has 2 ToolStripStatusLabel s followed by
We have hidden the status bar in our application. But when there is an
I have an iPhone app that hides the status bar. However, my main view
I have this critical issue with showing top statusbar on the custom camera overlay
I have made an application that can render and save a given element. With
I am making an application with Java Swing and i have a problem. I
I have 'StatusBar' with 'StatusBarItem'`s and one of them is current status label. I
I have a StatusBar that I'd like to house a TextBlock docked to 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.