简体   繁体   English

JavaFX中心图像不起作用

[英]JavaFX center an image doesn't work

I am having a problem. 我有问题。 I am trying to create an FXML(image) which I will use within another another FXML file. 我正在尝试创建一个FXML(图像),该图像将在另一个FXML文件中使用。 In the image FXML I want to change the image and center it, so I always want the image to be in the center, but it doesn't work. 在图像FXML中,我想更改图像并将其居中,因此我始终希望图像位于居中,但是它不起作用。 I am having this right now: 我现在有这个:

<fx:root fx:id="vBox" alignment="CENTER" maxHeight="-Infinity"   maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" type="javafx.scene.layout.VBox" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
    <children>
          <ImageView fx:id="imageView" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" VBox.vgrow="ALWAYS" />
    </children>
</fx:root>

Can someone help me with this? 有人可以帮我弄这个吗? This image sticks to the left side. 该图像粘贴在左侧。

fx:id="vBox" type="javafx.scene.layout.VBox" 

将您的容器更改为StackPane ,它将自动使图像居中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM