java - Updating GUI thread from another thread -
java - Updating GUI thread from another thread -
this question has reply here:
thread updating gui on dispatcher thread causes exception 1 replyi'm little confused multi threading in java, have gui created thread , project acts server , used receive info other info sources on separate thread. server's thread calls method in 1 of views on gui thread , updates status, gui doesn't update. how can setup architecture correctly. here's have:
public static void main(string[] args) { //connections runnable r2 = new runnable() { @override public void run() { app.connecttoserver(); } }; //launch main window runnable r1 = new runnable() { @override public void run() { //installs theme weblookandfeel.install(); //launches main window bootwindow mymainwindow = new bootwindow(); } }; thread thr1 = new thread(r1); thread thr2 = new thread(r2); thr1.start(); thr2.start(); } //server connections private static void connecttoserver() { system.out.println("connecting etrade manager server.."); etmserver server = new etmserver(); server.connectetmserver(); }
if using awt/swing, gui runs on special thread called event dispatch thread (edt) , gui updates must run on thread. need instead:
swingutilities.invokelater(new runnable() { public void run() { //code goes here } });
keep in mind swing single-threaded , not thread-safe.
java multithreading swing
Comments
Post a Comment