Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8106067

Changing Stage.scene.contents fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • fx1.0.1
    • javafx
    • None
    • Windows XP, 6u10, 1.0.1.

      The attached file creates two n x n arrays of rectangles (one red, one blue) and a stage that contains the sequence that represents the first array in its scene.content. It then uses a Timeline to switch arrays every s seconds. Various problems occur:
      a- sometimes the window has just a title bar and no content, eg, its height and width are 0.

      -b sometimes, the switch to the other sequence doesn't work.

      -c sometimes the process starts using 100% of the CPU and has to be killed with the Window Task Manager. I think this and b always happen at the same time, but I am not sure of that. This can usually be observed with the interval set to 1s and ncells set to 60.

      -d when it is running correctly, sometimes moving another window on top of the program's window, or moving the mouse around the program's window causes c and/or b. This can be seen if the interval is set higher, eg, 3 secs which seems to prevent b/c from happening spontaneously.

      -e if you change the run() function so that doit() is called to do the swapping instead of using the Timeline, then no swapping occurs - the rectangles start out blue and never turn red.


      package test1;

      import javafx.stage.Stage;
      import javafx.scene.Scene;
      import javafx.scene.Group;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.text.Text;
      import javafx.scene.text.Font;
      import javafx.scene.paint.Color;
      import javafx.animation.Timeline;
      import javafx.animation.KeyFrame;

      def ncells = 60;
      def interval = 1s;
      var count = 0;

      var rects1 =
      for (i in [0..
      ncells * ncells - 1]) {
          Rectangle {
              width:10
              height: 10
              translateX: 12 * (i mod ncells) // ((i - ((i / 50) * 50)) as Integer)
              translateY: 12 * ((
              i / ncells) as Integer)
              fill: Color.BLUE
          }
      }

      var rects2 =
      for (i in [0..
      ncells * ncells - 1]) {
          Rectangle {
              width:10
              height: 10
              translateX: 12 * (i mod ncells) // (( i - ((i / 50) * 50)) as Integer)
              translateY: 12 * ((
              i / ncells) as Integer)
              fill: Color.RED
          }
      }
      var ss = Stage {
          title: bind "{count}, interval = {interval}, ncells = {ncells}"
          width: 700
          height: 700
          scene: Scene {
              content: rects1
          }
      }


      var tt = Timeline {
          repeatCount: Timeline.INDEFINITE
          keyFrames: [
              KeyFrame {
                  time: interval
                  action: function() {
                      count++;
                      if (ss.scene.content == rects1) {
                          println("jj to red: {count}");
                          ss.scene.content = rects2;

                      } else {
                          println("jj to blue: {count}");
                          ss.scene.content = rects1;
                      }
                      println("jj: done");
                  }
              }
          ]
      }
      //tt.play();

      function doit() {
          while (true) {
              java.lang.Thread.sleep(3000);
              count++;
              if (ss.scene.content == rects1) {
                  println("jj to red: {count}");
                  ss.scene.content = rects2;
              } else {
                  println("jj to blue: {count}");
                  ss.scene.content = rects1;
              }
              println("jj: done")
          }
      }

      function run() {
          //doit();
          tt.play();
      }


            kcr Kevin Rushforth
            jholmlundjfx Jim Holmlund (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: