I am trying to learn how to display images in JavaFX. In order to learn, I tried to create this simple program. However, the image does not display in the application.
package imagedemo;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
public class ImageDemo extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
//Create Image and ImageView
Image image = new Image("file:testImage.JPG");
ImageView iv = new ImageView(image);
//Create HBox, Scene, and Stage
HBox hbox = new HBox(iv);
Scene scene = new Scene(hbox);
primaryStage.setScene(scene);
primaryStage.show();
}
}
When I run the program, the result is: an empty application window. Are there any solutions that will cause the image to appear on the application as it should?
Edit 1: I am using NetBeans IDE 8.2 for this program in case anyone needs to know.