Reputation: 75
I have a problem while trying to add image in my scene in the javafx gluon application using the line bellow I put the img.jpg file in the pin folder
Imageview image = new ImageView(new Image("file: img.jpg"));
and also using ("/img.jpg") any suggestions ?
Upvotes: 1
Views: 521
Reputation: 17359
Your image should be stored under src/main/resources
folder according to a Gradle project structure. Usually it should be under the same package as your class, in this case the following code will load the image:
Image image = new Image(YourClass.class.getResource("img.jpg").toExternalForm());
ImageView imageView = new ImageView(image);
More information about loading resources in Java can be found at https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource(java.lang.String)
Upvotes: 1