title: JavaFX Pagination: setPageCount(int) calls the page factory again but does not show the page
body: <h2>Pre-story:</h2>
  
  <p>Ok so i had another problem with a custom pagination control and thought i had figure out why it didn't work as expected. However it still didn't work. So i created a min example to find out what was happening and if something else in my code was messing it up.</p>
  
  <h2>Problem</h2>
  
  <p>When setting the page count, the page factory gets called again, but the page that is being returned is not displayed. And I just can't figure out why.</p>
  
  <hr>
  
  <p><strong>Additional information for the code example:</strong></p>
  
  <p>If you comment out the setPageCount(4) the "initial page" will load. However when you do not comment it out, everything will only work if you switch pages or resize.</p>
  
  <p><strong>Edit:</strong> I was also wondering why the page factory is called at all if my current page is lower then the new page count. seems so weird - shouldn't it only call the page factory, if my new page count is lower then my current page index in addition to changing the current page index to 0?</p>
  
  <hr>
  
  <h2>Code - Minimal Working Example</h2>
  
  <pre><code>import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.control.Pagination;
  import javafx.scene.layout.Background;
  import javafx.scene.layout.BackgroundFill;
  import javafx.scene.layout.StackPane;
  import javafx.scene.layout.TilePane;
  import javafx.scene.paint.Color;
  import javafx.stage.Stage;
  
  public class Main  extends Application{
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) throws Exception {
  
          StackPane root = new StackPane();
          Pagination pagination = new Pagination();
  
          pagination.setPageFactory( index -&gt; {
              TilePane tilePane = new TilePane();
              System.out.println("Trace: start: createTilePane");
              System.out.println("TilePane: " + tilePane);
  
              tilePane.widthProperty().addListener( observable -&gt; {
                  System.out.println("WidthProperty-Listener");
                  System.out.println("tilePane: w: " + tilePane.getWidth() + "; h: " + tilePane.getHeight());
              });
              tilePane.heightProperty().addListener( observable -&gt; {
                  System.out.println("HeightProperty-Listener");
                  System.out.println("tilePane: w: " + tilePane.getWidth() + "; h: " + tilePane.getHeight());
                  pagination.setPageCount(4);
              });
              tilePane.setOnMouseClicked( event -&gt; {
                  System.out.println("Trace: onMouseClicked()");
                  System.out.println("tilePane: " + tilePane);
              });
              tilePane.setBackground(new Background(new BackgroundFill(Color.BEIGE, null, null)));
  
  
              System.out.println("Trace: end: createTilePane");
              return tilePane;
          });
  
          root.getChildren().add(pagination);
  
          Scene scene = new Scene(root, 500, 500);
  
          primaryStage.setScene(scene);
          primaryStage.show();
  
      }
  }
  </code></pre>