How can I load Computer Directory images in JAVAFX

It is not clear exactly what you are trying to do. If you are talking about JavaFX 2.0, the following code works. If you are loading a lot of images and need to conserve memory, you only have to create enough ImageView’s for the number you want to display at one time. Then as you page through the images, you can swap out the Image object contained in the ImageView.

public void start(Stage primaryStage) {
    primaryStage.setTitle("Hello World");
    StackPane root = new StackPane();
    Scene scene = new Scene(root, 300, 250);

    File file = new File("/System/Library/CoreServices/loginwindow.app/Contents/Resources/LogOut.png");
    Image image = new Image(file.toURI().toString());
    ImageView iv = new ImageView(image);

    root.getChildren().add(iv);
    primaryStage.setScene(scene);
    primaryStage.show();
}

Leave a Comment