Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    force Label to redraw()

    Hello, I would like to force a Label to redraw at a specific time.
    How this could be done?
    I am trying the following code, but still the Label redraw itself at the end of the loop.
    I would like to see each one of the numbers...

    Code:
    public class MainEntryPoint implements EntryPoint
    {
      private VLayout v;
      private Label label;
      public void onModuleLoad ()
      {
        v = new VLayout ();
    
        label = new Label ("hello");
        v.addMember (label);
    
        Button btn = new Button ("test redraw");
        btn.addClickHandler (new ClickHandler ()
                                {
                                  public void onClick (ClickEvent event)
                                  {
                                    onTest ();
                                  }
                                });
        v.addMember (btn);
        v.draw ();
      }
      public void onTest ()
      {
        for (int i=0; i<500; i++)
        {
          label.setContents (""+i);
          label.markForRedraw ();
          v.reflowNow ();
          label.redraw ();
          v.redraw ();
        }
      }
    }
    Any ideas?


    Thank you again

    Yorgos Tryfon.

    #2
    redraw() is the right way to do it, however, in your code below there is no need for any of those calls beyond setContents().

    What makes you think this is not working?

    Comment


      #3
      What makes you think this is not working?

      Because I see only the last message on the screen "499".
      (after when the job is completed - after some seconds)

      Comment


        #4
        Right.. because you've only created one Label!

        Comment


          #5
          Thank you for your reply, but I insist...
          I just tried:
          Code:
          public class MainEntryPoint implements EntryPoint
          {
            private VLayout v;
            private Label label;
            public void onModuleLoad ()
            {
              v = new VLayout ();
          
              label = new Label ("hello");
              v.addMember (label);
          
              Button btn = new Button ("test redraw");
              btn.addClickHandler (new ClickHandler ()
                                      {
                                        public void onClick (ClickEvent event)
                                        {
                                          onTest2 ();
                                        }
                                      });
              v.addMember (btn);
              v.draw ();
            }
            public void onTest2 ()
            {
              Window.alert ("start");
              for (int i=0; i<500; i++)
              {
                  v.removeMember (label);
                  label = new Label (""+i);
                  v.addMember (label);
                  v.redraw ();
              }
              Window.alert ("stop");
            }
          }
          I am creating new Labels now and replacing them in the VLayout.
          Still I don't see the changes. only the last one

          Does it work OK in your browser?

          Comment


            #6
            Great - now remove Window.alert(), which stops all execution.

            Comment


              #7
              I would like to be like this,
              I removed both Window.alert and I tested it in Chrome, Firefox, IE
              no, it just waits untill to display the last change.

              Comment


                #8
                Is this intended as a puzzle or something? Each iteration of the loop, you remove the label you added last time. So you still end up with only one.

                Adding a series of labels to a VLayout works, if it didn't, nothing that SmartGWT does would be possible.

                Comment


                  #9
                  > if it didn't, nothing that SmartGWT does would be possible.

                  I thing there is some misunderstanding here.
                  What I do is this:

                  I add a Label and I try to redraw()

                  then I remove the Label and I add another one and I try to redraw()

                  then I remove the Label and I add another one and I try to redraw()

                  then I remove the Label and I add another one and I try to redraw()

                  ...

                  I would like to see all the changes (that's all)

                  SmartGWT does the additions and the removals, it is the redraw() that is not working untill for the browser to be free from other jobs.

                  I hope Idescribet it better now.
                  If you want you may copy my code and run it in a test project, see by yourself.

                  Best regards

                  Yorgos Tryfon

                  Comment


                    #10
                    The updates just happen too fast. Try this:
                    Code:
                        private VLayout v;
                        private Label label;
                    
                        public void onModuleLoad() {
                            v = new VLayout();
                    
                            label = new Label("hello");
                            v.addMember(label);
                    
                            Button btn = new Button("test redraw");
                            btn.addClickHandler(new ClickHandler() {
                                public void onClick(ClickEvent event) {
                                    Window.alert("start");
                                    timedTest(0);
                                }
                            });
                    
                            v.addMember(btn);
                            v.draw();
                        }
                    
                        public void timedTest(final int count) {
                    
                            v.removeMember(label);
                            label = new Label("" + count);
                            v.addMember(label);
                            v.redraw();
                    
                            if (count < 50) {
                                new Timer() {
                                    public void run() {
                                        timedTest(count + 1);
                                    }
                                }.schedule(50);
                            } else
                                Window.alert("stop");
                        }
                    Last edited by nlotz; 17 Apr 2009, 23:38.

                    Comment


                      #11
                      Thank you for this post,
                      I have found also some solusion using Timer, but it is not ver neat
                      and I would like something simpler if possible.

                      Best regards.

                      Yorgos Tryfon

                      Comment


                        #12
                        Are you trying to do something like an animation here, that is, show a single label changing through a series of text values? If so, yes you need timers. Generally speaking browsers do not redraw until the current JavaScript thread exits.

                        Comment


                          #13
                          I just want to display a single "Please wait..." before starting some process.
                          I want the "Please wait..." to be displayed before the process and not after.

                          Comment


                            #14
                            Display "Please wait..", set a Timer, then proceed with the long process when the Timer fires. That's the only way to do it, as again, generally browsers do not redraw until the current JavaScript threads exits.

                            Next time you have a question like this, please don't start with an arbitrary unrelated piece of code that appears to have to do with trying to stack a bunch of labels. That was a big waste of time. Start instead with a very high-level description of what you want to achieve, like you just did now.

                            Comment


                              #15
                              Thank you for this advice, I already did this with the timer.

                              Comment

                              Working...
                              X