首页 > 解决方案 > 如何使 GridPane 中的 ImageView 图像可调整大小?

问题描述

GridPane在所有ImageView包含图像的单元格中都有一个和。当我更改窗口大小时,我成功地GridPane调整了大小。

问题是当GridPane图像变大时,图像不会增长。我知道您可以通过以下方式使它们在全屏时适合:

imageView.setFitHeight(100);
imageView.setFitWidth(100);

使用此代码,图像在非全屏时会太大。

我想让它们在窗口模式下适合perfectly(Fit(80))单元格,以及Fullscreen(Fit(100)).

我的(不太好看)的想法是有一个类似的方法:

if(stage.inFullscreen) { setFitHeight/Width(100)};
if(stage.inWindowscreen) { setFitHeight/Width(80)};

还有其他更优雅的方式吗?

我的代码的一部分:

<GridPane fx:id="Board" layoutY="-1.0" prefHeight="800.0" prefWidth="836.0">
              <columnConstraints>
                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                  <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
...

标签: javajavafxfxmlgridpane

解决方案


推荐阅读