我有FXML表格,结构如下。我尝试以不同的方式将图像加载到图像视图中。但是,它无法正常工作。
<GridPane alignment="TOP_CENTER" prefWidth="800.0" styleClass="header" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="228.0" minWidth="10.0" percentWidth="50" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="261.0" minWidth="10.0" fillWidth="true" percentWidth="50" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" valignment="CENTER" vgrow="ALWAYS" />
</rowConstraints>
<children>
<ImageView GridPane.columnIndex="0" GridPane.rowIndex="0"
fx:id="ImgViewBanner"
pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:src/images/banner.png" backgroundLoading="true" />
</image>
</ImageView>
<VBox GridPane.columnIndex="1" GridPane.rowIndex="0">
<Label text="English - English">
<font>
<Font size="48" />
</font>
</Label>
<Label text="Advanced Learners' Dictionary" >
<font>
<Font size="24" />
</font>
</Label>
</VBox>
</children>
</GridPane>
我把我的图像放在这些目录下。
答案 0 :(得分:0)
由于您的映像与fxml文件位于同一目录中,因此您应该能够使用@
指定相对于fxml文件的资源位置:
<Image url="@banner.PNG" backgroundLoading="true" />