0

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

enter image description here

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

enter image description here

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:

enter image description here

saltyeggs
  • 63
  • 1
  • 7
  • From the looks of your layout structure, I would recommend you spend more time learning about the layout nodes. I just can't imagine the use-case for all of those nested `SplitPanes`. – SedJ601 Apr 01 '21 at 15:50
  • 1
    Does it run? This just sounds like IntelliJ not understanding expression binding. – James_D Apr 01 '21 at 15:51
  • @Sedrick I will look more at layout structure but do you think reducing the number of splitpanes will resolve the issue with the contents of a scrollpane not scaling when the window resizes or is there some other issue? – saltyeggs Apr 02 '21 at 09:28
  • @James_D it does not run with the expression, the error output is here: https://pastebin.ubuntu.com/p/sCF6sx9sZ8/ It should though, right? – saltyeggs Apr 02 '21 at 09:28
  • Post your complete FXML. I can have a look. – SedJ601 Apr 02 '21 at 14:43
  • In other words, please create and then post a [mre] demonstrating the problem. – Slaw Apr 02 '21 at 16:34

0 Answers0