Java 在父边框窗格中居中并调整ImageView的大小
我有以下FXML:Java 在父边框窗格中居中并调整ImageView的大小,java,layout,javafx,imageview,Java,Layout,Javafx,Imageview,我有以下FXML: <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.image.*?> <?import javafx.scene.effect.*?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import java.lang.*?> <?import j
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import javafx.scene.effect.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<BorderPane fx:id="mainBorderPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.mho.livepicture.server.ui.presenter.UIPresenter">
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="Datei">
<items>
<MenuItem mnemonicParsing="false" onAction="#exit" text="Beenden" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Hilfe">
<items>
<MenuItem mnemonicParsing="false" text="Über..." />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<bottom>
<HBox alignment="CENTER_RIGHT" spacing="6.0" BorderPane.alignment="CENTER_RIGHT">
<children>
<Button fx:id="startStopServerButton" mnemonicParsing="false" onAction="#startStopServer" text="Server starten" />
<Button mnemonicParsing="false" onAction="#exit" text="Beenden">
<opaqueInsets>
<Insets />
</opaqueInsets>
<HBox.margin>
<Insets />
</HBox.margin>
</Button>
</children>
<BorderPane.margin>
<Insets bottom="6.0" left="6.0" right="6.0" top="6.0" />
</BorderPane.margin>
</HBox>
</bottom>
<center>
<ImageView fx:id="imageView" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
我不知道如何让ImageView调整BorderPane中心可用空间的大小。它始终使用舞台/场景的整个可用大小。尝试将节点添加到
边框窗格的左侧
和右侧
。这将防止ImageView
占据整个空间。它将填满空间,因为您已将mainBorderPane
的宽度和高度绑定到primaryStage
,然后将ImageView
的宽度和高度绑定到mainBorderPane
mainBorderPane.prefWidthProperty().bind(primaryStage.widthProperty());
mainBorderPane.prefHeightProperty().bind(primaryStage.heightProperty());
imageView.setImage(new Image(MAIN_ICON_BLACK_URL));
imageView.fitWidthProperty().bind(mainBorderPane.widthProperty());
imageView.fitHeightProperty().bind(mainBorderPane.heightProperty());