I want to set the prefHeight of an AnchorPane to 4 times the height of a GridPane. I have read in another post that this should be possible, at least for other elements:
Is it possible to use arithmetic expression in FXML?
I am able to reference the height of the GridPane alone by itself fine like so:
<AnchorPane fx:id="imagesAnchorPane" prefHeight="${buttonsGridPane.height}" minHeight="250.0" prefWidth="135.0">
but once I try to use prefHeight="${buttonsGridPane.height * 4}"
the * 4
is highlighted red and the mouseover IntelliJ displays the error:
Cannot resolve symbol 'height * 4' with references to javafx.scene.layout.Region private javafx.beans.property.DoubleProperty prefHeight
Same issue using 4 or 4.0 for all of the steps I have tried.
In an effort to more closely follow the proposed solutions in the linked post I also tried defining a double with the same arithmetic as to use it directly for the prefHeight but this will not even recognise the height reference alone, instead erroring with
Invalid value: Unable to coerce to java.lang.Double
I am able to define it as a String, but when I then try to then multiple that String by 4 I receive the same error about unable to coerce to double:
<fx:define>
<String fx:id="xHeight" fx:value="${buttonsGridPane.height}"/>
<Double fx:id="yHeight" fx:value="${xHeight * 4}"/>
</fx:define>
I also have a method that will change the value, which I can call with onMouseClicked, but I have not been able to find a way to use it for an attribute as I expect this is not allowed:
private void fixScale(){
imagesAnchorPane.setPrefHeight(buttonsGridPane.getHeight() * 4);
}
For reference this is all in an effort to make it so that the AnchorPane, which is holding a GridPane of images will scale with the rest of the program when the window is resized as it is not. Although this AnchorPane may become a Java object, right now it has been implemented using SceneBuilder and opening tags of the FXML code is the following:
<SplitPane dividerPositions="0.503708281829419" layoutX="24.0" layoutY="45.0" prefHeight="265.0" prefWidth="324.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" style="-fx-background-color: #bbc4c4; -fx-border-color: #323636; -fx-border-insets: 3; -fx-border-radius: 3; -fx-border-width: 2;">
<children>
<ScrollPane fitToWidth="true" hbarPolicy="NEVER" layoutX="-20.0" layoutY="33.0" prefHeight="265.0" prefWidth="160.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<AnchorPane fx:id="imagesAnchorPane" minHeight="250.0" onMouseClicked="#fixScale" prefWidth="135.0">
<children>
<GridPane prefHeight="574.0" prefWidth="135.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="0.0">
And this is the current structure from the top level AnchorPane down to the imagesGridPane: