设置JavaFX ImageView的最大大小 [英] Set maximum size for JavaFX ImageView

查看:327
本文介绍了设置JavaFX ImageView的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会根据场景调整图像视图的大小,但是即使场景大于图像原始大小,图像也会继续调整大小.

I resize the image view according to the scene but image keep resizing even if the scene is bigger than image original size.

我已经设置了ImageView.maxWidth(originalImageWidth),但是它不起作用.

I have set ImageView.maxWidth(originalImageWidth) but it did not work.

我通过将ImageView的大小绑定到场景大小来调整其大小.

I resize the ImageView by binding it's size to the the scene size.

推荐答案

这可行

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);

这篇关于设置JavaFX ImageView的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆