在 FXML 中显示图像

问题描述 投票:0回答:1

我想在 javaFX 中显示某个图像,因此我在 FXML 文件中创建它,以便稍后在controller.java 文件中对其进行操作,但我不断收到一个又一个错误。这是最新的了

Caused by: javafx.fxml.LoadException: Attributes are not supported for writable property elements.
/C:/Users/ASUS/eclipse-workspace/sample/bin/sample/sample.fxml:263
at sample.Main.start(Main.java:12)
Exception running application sample.Main

这是我写的简单代码:

<ImageView fx:id="imageView" fitHeight="150.0" fitWidth="200.0" layoutX="61.0" layoutY="83.0" pickOnBounds="true" preserveRatio="true" >
                <image url="file:///C:/Users/ASUS/Desktop/projet/logo.png" backgroundLoading="true"/>
</ImageView>
java eclipse image javafx fxml
1个回答
0
投票

显示图像的 FXML 示例:

<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
   <image>
      <Image url="@../../Pictures/Planet.png" />
   </image>
</ImageView>

此示例是使用 SceneBuilder 创建的(如果使用 FXML,我建议使用它,而不是从头开始手动编写 FXML)。

© www.soinside.com 2019 - 2024. All rights reserved.