Re: [Java-gnome-developer] Problem with Threading (I guess)
Brought to you by:
afcowie
From: Emmanuel R. <emm...@gm...> - 2006-09-17 21:00:03
|
Hi, I think that the problem is because you are accessing your widgets from your second thread. Only the event loop thread is allowed to manipulate the widgets. Take a look at the following page there is an explanation and some sample code. http://java-gnome.sourceforge.net/cgi-bin/bin/view/Main/MultiThreaded Stefan Prelle wrote: > Hi all, > > I am trying to build a splashscreen that shows the process while the > application is loading data. I found that after a short time, no > progress changes are visible while the loading continues. > > I broke my problems down to a simple test program that forks a thread to > change the progress and that waits a specific amount of time between two > changes. > > public class SplashTest { > > static ProgressBar bar; > static TextView text; > > //------------------------------------------------------ > public static void main(String[] args) { > Gtk.init(args); > > // Open a window with a progress bar and a text view. > Window window = new Window(); > VBox box = new VBox(false,5); > window.add(box); > bar = new ProgressBar(); > box.add(bar); > text = new TextView(); > box.add(text); > window.showAll(); > > // Now create progress changing thread > Thread thread = new Thread(new Runnable(){ > public void run() { > for (int i=0; i<=100; i+=10) { > System.out.println("Now "+i); > bar.setFraction(i/100.0); > bar.setText(i+"%"); > text.getBuffer().setText("Loaded "+i+"%"); > synchronized(this) { > try { > Thread.sleep(1000); > } catch (InterruptedException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > } > }}); > > thread.start(); > Gtk.main(); > } > } > > When I do run this program, the progress bar stops at 10 or 20 percent, > the text view stops at 0 or 10 percent. > If you reduce the waiting time between changes to a lower value - e.g. > 500ms - everything is fine. > > Any idea what is causing this? > > Regards, > Stefan > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > java-gnome-developer mailing list > jav...@li... > https://lists.sourceforge.net/lists/listinfo/java-gnome-developer > > |