问题
I resize the image view according to the scene but image keep resizing even if the scene is bigger than image original size.
I have set ImageView.maxWidth(originalImageWidth) but it did not work.
I resize the ImageView by binding it's size to the the scene size.
回答1:
This would work
Pane root = new VBox(); //or other Pane sub-class
ImageView bg = new ImageView(...);
bg.setPreserveRatio(false);
bg.fitWidthProperty().bind(root.widthProperty());
bg.fitHeightProperty().bind(root.heightProperty());
root.getChildren().addAll(bg);
回答2:
May not be too relevant anymore but i found a solution that works for me at least:
- set setPreserveRatio to true,
- set fitHeight to the wanted maximum width * ratio
- bind the fitWidthProperty to the screnes widthProperty
In other words: you can bind one dimension and have a maximum fit size to the other at the same time.
来源:https://stackoverflow.com/questions/21501090/set-maximum-size-for-javafx-imageview