I'm creating a stage that I've made in scenebuilder and I want some of the sizes in there to be dependent on the size of the monitor. However, in scenebuilder, when setting pref width/height, I can only write a number or "USE_COMPUTED_SIZE". I know that I can get the dimensions of the screen by using the following code;
Rectangle2D screenBounds = Screen.getPrimary().getBounds();
@FXML
double windowHeight = screenBounds.getHeight()/2;
@FXML
double windowWidth = screenBounds.getHeight()/2;
is there a way to use these variables "windowHeight" and "windowWidth" in the FXML file. Like:
<AnchorPane prefHeight="windowHeight" prefWidth="windowWidth" stylesheets="@defaultStyle.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Menu">
(The variables "windowHeight" and "windowWidth" are declared in Menu.java)
Another preferred way to be able to do it would be if I could directly set the width and height to a variable within scenebuilder.
Perhaps, even better would be if I could set all values within scenebuilder to be by preferred ratio rather that size, so that later on, when resizing the stage, everything would change with it.
I have tried to later set the width and height of the stage when loading it but it didn't really work.