title: Javafx NumberBinding rounding
body: <p>I'm working on my first JavaFX Application and I'm having troubles with a NumberBinding. I have this NumberBinding : </p>
  
  <pre><code>NumberBinding cellSize = Bindings.min(scene.widthProperty().subtract(150).divide(nbC.getValue()), scene.heightProperty().subtract(150).divide(nbR.getValue()));
  </code></pre>
  
  <p>Then I put panes having <code>widthProperty()</code> and <code>heightProperty()</code> bound to this <code>cellSize</code> to my <code>GridPane gPane</code>.</p>
  
  <p>And the thing I want to is have a label have the same width and height as the <code>GridPane</code>, so that I put both in a StackPane and so the label is over the <code>GridPane</code> totally covering it.</p>
  
  <p>I've tried to bind the label <code>prefWidthProperty()</code> and <code>prefHeightProperty()</code> to the width and height properties of the <code>gPane</code> but it doesn't work, since the real width and height of it doesn't seem to be the number of columns and rows multiplied by cellSize.</p>
  
  <p>So the code I'm using right now is this one :</p>
  
  <pre><code>winLabel = new Label("Bravo vous avez gagné ! :)");
  winLabel.prefWidthProperty().bind(cellSize.multiply(nbC.getValue()));
  winLabel.prefHeightProperty().bind(cellSize.multiply(nbR.getValue()));
  </code></pre>
  
  <p>It works well, except that the label is a little bit smaller than my panes and sometimes the size of the panes just jumps a few pixels at once, in which case the label size corresponds to the panes size.
  I supposed it was due to cellSize being rounded up (so the jump in size would be when we get closer to the next rouding value).</p>
  
  <p>I've tried to fix it for 2 hours using <code>DoubleBinding</code> and trying everything but I don't seem to be getting anywhere. Can you help me please ?</p>
  
  <p>Here's an mvce :</p>
  
  <pre><code>public class Mvce extends Application {
  
      private Scene scene;
      // will be the root of our scene
      private AnchorPane anchor;
  
      private GridPane gPane;
      private Label winLabel;
  
      // this stackPane will contain the grid and the winLabel
      private StackPane stack;
  
      // number of columns and rows, from which we calculate the binding cellSize
      private IntegerProperty nbC;
      private IntegerProperty nbR;
      private NumberBinding cellSize;
  
      private static final int WINDOW_SIZE=720;
  
      public void addWinLabel(){
          DoubleProperty fontSize = new SimpleDoubleProperty();
          fontSize.bind(cellSize.multiply(nbC.getValue()).divide(15));
  
          winLabel = new Label("Congratulations, you won ! :)");
          winLabel.prefWidthProperty().bind(cellSize.multiply(nbC.getValue()));
          winLabel.prefHeightProperty().bind(cellSize.multiply(nbR.getValue()));
  
          winLabel.setTextFill(Color.web("#3099AA"));
          winLabel.setAlignment(Pos.CENTER);
  
          winLabel.styleProperty().bind(Bindings.concat("-fx-font-size: ", fontSize.asString(), ";",
                                                        "-fx-background-color: rgba(200, 200, 200, 0.85);"));
  
          anchor.getChildren().add(winLabel);
          anchor.setTopAnchor(winLabel, 75.0);
          anchor.setLeftAnchor(winLabel, 75.0);
      }
  
      public void createPanes(){
          anchor.getChildren().remove(stack);
          stack = new StackPane();
          gPane = new GridPane();
          cellSize = Bindings.min(scene.widthProperty().subtract(150).divide(nbC.getValue()), scene.heightProperty().subtract(150).divide(nbR.getValue()));
  
          for(int c=0; c&lt;nbC.getValue(); c++){            
              for(int r=0; r&lt;nbR.getValue(); r++){
                  if(c==0){
                      RowConstraints row = new RowConstraints();
                      row.setPercentHeight(100/nbR.getValue());
                      gPane.getRowConstraints().add(row);
                  }
  
                  Pane pane = new StackPane();
  
                  pane.minWidthProperty().bind(cellSize);
                  pane.minHeightProperty().bind(cellSize);
                  pane.maxWidthProperty().bind(cellSize);
                  pane.maxHeightProperty().bind(cellSize);
  
                  pane.setStyle("-fx-background-color: #FFFFFF");
                  gPane.add(pane,c,r);
              }
          }
  
          gPane.setGridLinesVisible(true);
          stack.getChildren().addAll(gPane);
          anchor.getChildren().add(stack);
          anchor.setTopAnchor(stack, 75.0);
          anchor.setLeftAnchor(stack, 75.0);
  
          addWinLabel();
      }
  
      @Override
      public void start(Stage primaryStage) {
          primaryStage.setMinWidth(720.0);
          primaryStage.setMinHeight(720.0);
  
          // main panes
          anchor = new AnchorPane();
          scene = new Scene(anchor, WINDOW_SIZE, WINDOW_SIZE, Color.LIGHTBLUE);
  
          nbC = new SimpleIntegerProperty(7);
          nbR = new SimpleIntegerProperty(7);
  
          createPanes();
  
          primaryStage.setTitle("mvce");
          primaryStage.setScene(scene);
  
          primaryStage.show();
      }
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>