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

Force scene refresh inside swing

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • fx2.1.1, fx2.1, 7u6
    • fx2.1.1, fx2.1, 7u6
    • javafx

      I have a Java swing application with a JFXPanel inside. I have a Jbutton that modifies the value of a javafx object(Scale), like this:

          private final Scale sceneScale;

      [...]

      scenarioGroup = new Group();
      scene = new Scene(scenarioGroup, Color.TRANSPARENT);
      scenarioGroup.setCacheHint(CacheHint.SPEED);
      sceneScale = new Scale(1, 1, 0, 0);
      scenarioGroup.getTransforms().add(sceneScale);

      [...]
          //This method is called from JButton
          public void setZoomLevel(final double zoomLevel) {
              Platform.runLater(new Runnable() {

                  @Override
                  public void run() {
                      sceneScale.xProperty().set(zoomLevel);
                      sceneScale.yProperty().set(zoomLevel);
                  }
              });
          }

      But I have an error.Sometimes the scale wasn't updated/refreshed/repainted until a shape was modified/added/removed/visibilityChange/etc by JavaFX mouse events.

      Then I search a lot to find out the problem:

      1st I try to add
                      scenarioGroup.requestLayout();
      after
                      sceneScale.xProperty().set(zoomLevel);
                      sceneScale.yProperty().set(zoomLevel);

      2nd I tryed to force a pulse with that:
                      Toolkit.getToolkit().requestNextPulse();

      So the code was like that:

          public void setZoomLevel(final double zoomLevel) {
              Platform.runLater(new Runnable() {

                  @Override
                  public void run() {
                      sceneScale.xProperty().set(zoomLevel);
                      sceneScale.yProperty().set(zoomLevel);
                      scenarioGroup.requestLayout();
                      Toolkit.getToolkit().requestNextPulse();
                  }
              });
          }

      It dint' fix anything and I dint' know what was going on, so I create some listeners of the scene and the stage:


                          Toolkit.getToolkit().addSceneTkPulseListener(new com.sun.javafx.tk.TKPulseListener() {

                              @Override
                              public void pulse() {
                                  System.out.println("SceneTkPulseListener");
                              }
                          });

                          Toolkit.getToolkit().addStageTkPulseListener(new com.sun.javafx.tk.TKPulseListener() {

                              @Override
                              public void pulse() {
                                  System.out.println("StageTkPulseListener");
                              }
                          });

      these listeners sometimes work, but sometimes don't. In fact, with the java 64bit version MOST of the times is perftect. With the 32 version with JavaFX 2.1.1 NEVER works. And with 32 bit and JavaFX 2.2.0-beta SOMETIMES.

      I also tried to modify the cache hints, so I added: "scenarioGroup.setCacheHint(CacheHint.SPEED);" with the same result.

      :|

      Thank you very much and congratulations, JavaFX is impressive.



            art Artem Ananiev (Inactive)
            dcirujanojfx Diego Cirujano (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: