FXML: An elegant way to bind a child width/height to the parent's width/height
fxml, javafx
Solution
Expression bindings work by referencing elements of the `FXMLLoader`'s namespace. There is no concept of "`this`" to refer to "the current node" (that I am aware of). So the only way to access the parent of a node is for the node itself to be part of the namespace: you can achieve this by setting an `fx:id` on the node itself:
<Pane>
<children>
<Node fx:id="node" prefWidth="${node.parent.width}"></Node>
<children>
</Pane>
Problem
I'm using FXML with JavaFX to develop graphical interfaces. I discovered this method for binding the width/height of a child node to the width/height of it's parent node: ``` <Node fx:id="parent"> <children> <Node prefWidth=${parent.width}></Node> <children> </Node> ``` But that feels inelegant. I'd rather not have to give an id to a node just so it's child can reference it's dimensions. Is there perahps some method for referenceing the `parent` of a node? Maybe something like `prefWidth=${parent.width}`? NOTE: I know this can be done programmatically from Java, but that's not what I want here. I'm looking for a way to do this in the FXML.