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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:42:30+00:00 2026-06-13T18:42:30+00:00

Hope my first question isn’t too obvious or badly researched. The below code is

  • 0

Hope my first question isn’t too obvious or badly researched. The below code is from the MouseListener’s mouseClicked event. I was hoping to change the border color to green to show the user what he/she has clicked on, start the sleep timer and then change it back to black. Unfortunately, the change only takes place after the Thread.sleep (and probably a whole host of methods). Currently the change back to black is commented and the color change does change to green (permanently). If it isn’t commented, there is no visible color change. What is going on here?

Thanks

    JLabel myLabel = (JLabel) e.getSource();
    myLabel.setBorder(BorderFactory.createLineBorder(Color.green));

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    //myLabel.setBorder(BorderFactory.createLineBorder(Color.black));
  • 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-13T18:42:31+00:00Added an answer on June 13, 2026 at 6:42 pm

    If you sleep in the event dispatch thread, you prevent it from doing its work, i.e. repaint the GUI and display the border you’ve just set. You’re just freezing the whole GUI for 2 seconds.

    You need to use a swing Timer, and have this timer reset the border to its original color after 2 seconds. The sleep must be done in another thread, and then the border must be changed in the EDT. That’s what the Swing Timer does for you.

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

Sidebar

Related Questions

I have a question about Excel! I hope that isn't too unconventional for this
I hope the title isn't too confusing, I'll try to explain better below. Suppose
First question. Hope this isn't a repeat. I have an unordered list of thumbnails
I am new here and hope my first question meets stack overflow's requirements. I
This is my first question on Stack Overflow, so I hope that I'm clear
This is my first question in this forum, so i hope to be clear:
Hello there Stack Overflow, I hope you'll help me with my very first question
This is my first time here so I hope I post this question at
First question on stackoverflow :) Hope I won't embarrass myself... I have a javascript
this my first question on here. I hope someone can help. It is 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.