You cannot get the image path from the image through a non-obsolete API, because such an API does not exist in Java 8. You can use the obsolete API and the risk of breaking your application in a future version of Java when the obsolete API is removed - this is not recommended. You can create a function request to make getURL () the public API on the image, but there is no guarantee that it will be accepted, and even if it was, it would only turn it into a later release of Java.
The image is not final, so I suggest the following:
class LocatedImage extends Image { private final String url; public LocatedImage(String url) { super(url); this.url = url; } public String getURL() { return url; } }
Create your image as follows:
Image image = new LocatedImage("fxml/images/bilhar9.png");
You can then access the URL through:
String url = image instanceof LocatedImage ? ((LocatedImage) image).getURL() : null;
Not a great solution, but may be enough for your case.
source share