Calculations like this are currently experimental technology for CSS 3 (see https://developer.mozilla.org/en/docs/Web/CSS/calc). JavaFX CSS is based on CSS 2.1.
Any multiplication of the size is only possible using the scale properties and this will behave a bit different to setting the prefered size to the result of a calculation.
@Override
public void start(Stage primaryStage) {
Button btn = new Button("Say 'Hello World'");
btn.setOnAction((ActionEvent event) -> {
System.out.println("Hello World!");
});
StackPane root = new StackPane();
root.setId("root");
root.getChildren().add(btn);
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
* {
-fx-scene-width: 500;
-fx-scene-height: 600;
}
#root {
-fx-pref-width: -fx-scene-width;
-fx-pref-height: -fx-scene-height;
}
.button {
-fx-pref-width: -fx-scene-width;
-fx-pref-height: -fx-scene-height;
-fx-scale-x: 0.8;
-fx-scale-y: 0.8;
}
Note that an attempt to set the size of the root to a different size than the scene size seems to be a bit non-sensical, since the Scene will set the root's size to it's own size regardless of any constraints specified on the root Node.
CSS is a good way of styling a scene in JavaFX, but it has some limitations. However you can use CSS and set/bind some values from code.