You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Edgar Merino <do...@gmail.com> on 2011/07/12 03:07:23 UTC

Task countdown and Labels

Hello, I'm trying to implement a simple countdown animation using a Task 
and a Label: when the task is executed, it goes through a loop that 
repeats five times and does two things here: update the label with the 
current counter and sleep a second. However, sometimes I don't see the 
label updating until some processing on the application is finished, is 
there a way to force the application to wait for the label to be updated 
first before trying to assign a different value to its text property? 
Here's some sample code:


public class CountdownTask extends Task {

     private Label label;

     public CountdownTask(Label label) {
         this.label = label;
     }

     public void execute() {
         for (int i = 5; i >= 0; i--) {
             label.setText(i+1);

             Thread.sleep(1000);
         }
     }
}

I've tried running this both sync and async and I always get the same 
result.

Thanks in advance,
Edgar Merino