(JavaFX)(SceneBuilder)如果所有内容都设置为锚平面,那么当窗口调整大小时,如何自动调整场景大小?

(JavaFX)(SceneBuilder)如果所有内容都设置为锚平面,那么当窗口调整大小时,如何自动调整场景大小?,java,javafx,resize,fxml,Java,Javafx,Resize,Fxml,fxml文件中的所有代码都设置在锚定窗格中,我想知道是否有一种简单的方法可以在调整窗口大小时允许整个场景自动调整大小 FXML文件: <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.image.Image?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.AnchorPane?>

fxml文件中的所有代码都设置在锚定窗格中,我想知道是否有一种简单的方法可以在调整窗口大小时允许整个场景自动调整大小

FXML文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>

<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="csgocaseopener.InventoryController">
   <children>
      <ImageView fitHeight="400.0" fitWidth="600.0" pickOnBounds="true">
         <image>
            <Image url="@back.png" />
         </image>
      </ImageView>
      <AnchorPane layoutX="38.0" layoutY="65.0" prefHeight="270.0" prefWidth="525.0" />
      <ImageView fx:id="backbtn" fitHeight="45.0" fitWidth="45.0" layoutY="-1.0" onMouseClicked="#handleInventoryBack" pickOnBounds="true" preserveRatio="true" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="-1.0">
         <image>
            <Image url="@backbtn.png" />
         </image>
      </ImageView>
   </children>
</fx:root>

ImaveView
fit to width/height属性绑定到
Stage
width/height属性。此解决方案不会保持图像比例,因此会变形

ImageView imageView = new ImageView(new Image(getClass().getResourceAsStream("test.png")));
//imageView.setPreserveRatio(true);  //uncomment to keep image ratio.
imageView.fitHeightProperty().bind(stage.heightProperty());
imageView.fitWidthProperty().bind(stage.widthProperty());

调整窗口大小时,
AnchorPane
正在调整大小。在给定的代码中,你用图像填充整个
场景
,所以我假设你想调整图像的大小以填充窗口。是的,我只想让所有东西都填充窗口的大小