[Java-gnome-developer] Problem with Threading (I guess)
Brought to you by:
afcowie
From: Stefan P. <pr...@tz...> - 2006-09-17 13:55:30
|
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 |