multithreading - Java update GUI while MainThread.join()? -


i try move jlabel position position b sequential in same x , y steps.. method works correctly, doesnt't update gui.. show code in following:

when don't call .join() method, code works, don't wait execution on thread... need function don't call when runs.. can me?

thread movethread = new thread( new runnable()      {          @override         public void run()          {             (int = 0; i<const.steinverschiebenschritte; i++)              {                 try                 {                     p_lbltomove.setlocation(p_lbltomove.getlocation().x + x_schritt, p_lbltomove.getlocation().y + y_schritt);                     system.out.println("setloc");                     thread.sleep(10);                 }                 catch (interruptedexception ex)                 {                     statuslog("interruptedexception");                 }             }             system.out.println("invokelater");               p_lbltomove.setlocation(p_lbltomove.getlocation().x + x_offset, p_lbltomove.getlocation().y + y_offset);         }     });        movethread.start();     try {         system.out.println("beforejoin");         movethread.join();         system.out.println("afterjoin");         system.out.println("------------------");     } catch (interruptedexception ex) {         logger.getlogger(spielfeld.class.getname()).log(level.severe, null, ex);     } 

swing single thread environment, meaning should not performing long running or blocking operations within context of event dispatching thread, equally, swing not thread safe, meaning should update ui within context of event dispatching thread.

see concurrency in swing more details.

depending on you're trying achieve use swingworker, see worker threads , swingworker more details, or swing timer, see how use swing timers more details

also remember, swing relies on layout managers of core work when comes positioning , sizing components, might find fighting layout mangers cause unexpected results

of course, have @ the universal tween engine , sliding layout or java: moving jlabel twice using timer


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -