我想创建一个像4个图片1个字的应用程序,但图像不显示。我也使用了SceneBuilder。我在SceneBuilder中插入图像,预览很好,但是当我运行主文件时,它不显示。我尝试使用窗格并添加ImageView使用.getChildren()和工作,但我不能包括FXML文件。所以,任何帮助将不胜感激,谢谢。图片不显示在JavaFx
Screenshot of the program when I run the main file
Screenshot of the preview from SceneBuilder
public class Main extends Application {
@FXML
private ImageView apple;
//Window
@Override
public void start(Stage primaryStage) throws Exception{
try
{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
Scene scene = new Scene(root, 546, 600);
primaryStage.setTitle("4 Pics 1 Word");
primaryStage.setResizable(false);
primaryStage.setScene(scene);
primaryStage.show();
}
catch (Exception e)
{
e.printStackTrace();
}
//Time display
}
public static void main(String[] args) {
launch(args);
}
}
编辑1:为ImageView的FXML代码:
<ImageView fx:id="apple" fitHeight="360.0" fitWidth="430.0" layoutX="53.0" layoutY="30.0" pickOnBounds="true">
<image>
<Image url="@../../Apple.jpg" />
</image>
</ImageView>
我想你的程序只是没有找到图像,但没有看到(缩短)的FXML文件,它不可能帮助你。 – mipa
对不起。我现在将添加它 – Djoker