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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:54:53+00:00 2026-05-26T09:54:53+00:00

As I discussed with Inerdia on the earlier post , something is still strange

  • 0

As I discussed with Inerdia on the earlier post,
something is still strange When I’m in some JPanel (EDT for sure-I checked with the method check) and then I call some animation thread(the thread extend Thread) to start, inside the thread I’m not on EDT by check.
So I guess I should be because animation should be on EDT, so I wrapped the animate method with runnable and invokeAndWait(), but still got that in the animation thread I’m not on EDT, while calling to that code as I said earlier is on EDT, so, my invokeLater seems not to place that animation on EDT? why is that?

Relevant code(before wrapping the animate method with runnable and passing to invoke later:
So, being on a JPanel there is a line:

Animate(trainRailRoadTrack);  

Implementation is:

void Animate(ArrayList<RailroadSquare> i_TrainRailRoadTrack) {
    ArrayList<JPanelRailoadSquare> playerRailoadPanelsTrack = getRelevantRailroads(i_TrainRailRoadTrack);
    new SuspendedAnimation(playerRailoadPanelsTrack).start();
    jPanelBoard1.GetGameManager().EmptyPlayerSolution();
}

private class SuspendedAnimation extends Thread
{
    private ArrayList<JPanelRailoadSquare> m_PlayerRailoadPanelsTrack;

    public SuspendedAnimation(ArrayList<JPanelRailoadSquare> i_PlayerRailoadPanelTrack)
    {
        m_PlayerRailoadPanelsTrack = i_PlayerRailoadPanelTrack;
    }

    @Override
    public void run()
    {
       m_IsAnimationNeeded = true;
       for (JPanelRailoadSquare currRailoadSquare: m_PlayerRailoadPanelsTrack)
       {
           System.out.println("Is on Event dispatch thread: "+SwingUtilities.isEventDispatchThread());
           currRailoadSquare.SetGoingTrain();
           repaint();                            
           try
           {
               Thread.sleep(150);

           }
           catch (InterruptedException e){}
           currRailoadSquare.UnSetGoingTrain();
           repaint();                       
    }
}
  • 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-26T09:54:54+00:00Added an answer on May 26, 2026 at 9:54 am

    Inside of SuspendedAnimation.run() you’re not on the EDT. That’s where you need to use invokeLater(), not when calling Animate():

    @Override
    public void run()
    {
        // We're outside the EDT in most of run()
        m_IsAnimationNeeded = true;
        for (JPanelRailoadSquare currRailoadSquare: m_PlayerRailoadPanelsTrack)
        {
            SwingUtilities.invokeAndWait(new Runnable() {
                // The code that "talks" to Swing components has to be put on
                // the EDT
                currRailoadSquare.SetGoingTrain();
                repaint();
            });
    
            // We want to keep sleeping outside the EDT.
            try
            {
                Thread.sleep(150);
            }
            catch (InterruptedException e){}
    
            SwingUtilities.invokeAndWait(new Runnable() {
                currRailoadSquare.UnSetGoingTrain();
                repaint();                       
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As discussed in Eric Lippert's blog post Closing over the loop variable considered harmful
I know this topic has been discussed but I think it has some differences.
I found something similar discussed, but it was while .NET 4.0 RC. As for
This problem is discussed in this question Android: Wrong item checked when filtering listview
Same problem was discussed earlier and I also knew that nothing, not also a
I know this has been discussed earlier but I couldn't find a satisfactory answer.
I understand this has been discussed before but since this post in late 2010
This was discussed earlier here Android, ListView IllegalStateException: "The content of the adapter has
(Not sure is this has been discussed before ...) When building SQL for category
As discussed elsewhere, NSTabView does not have a setBackgroundColor method and subclassing NSTabView and

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.