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 ?
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.