I have an ImageView inside an AnchorPane and I want to resize the Image in the same proposition as the AnchorPane resize.
Can someone explain me how to do that?
Many thanks in advance.
You can bind the image view's fitWidth
and fitHeight
properties to the width and height of the anchor pane:
imageView.fitWidthProperty().bind(anchorPane.widthProperty());
imageView.fitHeightProperty().bind(anchorPane.heightProperty());
If you also want to preserve the proportions of the image you are displaying, you can do
imageView.setPreserveRatio(true);
Only thing work for me. On the view, listen change of the AnchorPane and set ImageView Size
init {
myAnchorPane.widthProperty().addListener { observable, oldValue, newValue ->
myImageView.fitWidth = myAnchorPane.width
myImageView.fitHeight = 0.0
}
}
See this answer. Basically you can use the ImageViewPane
that you can include in your project.