I want to check if a given URL exists and it's an image, in order to create a new Image(String url)
from it. If the given URL is not an image then it should return an error.
You could do this with a RequestBuilder
-- just request the image URL, use the Response
's getHeaders()
method to get the content type, and check if it's an image.
I was looking for the same thing - I wanted to determine when image is not loaded from URL. There is an ErrorHandler for this purpose. Here's the code:
Image img = new Image("some_url/img.jpg");
img.addErrorHandler(new ErrorHandler() {
@Override
public void onError(ErrorEvent event) {
System.out.println("Error - image not loaded.");
}
});
Image img = new Image(); //no url parameter
img.addErrorHandler(new ErrorHandler() {
@Override
public void onError(ErrorEvent event) {
System.out.println("Error - image not loaded.");
}
});
img.setUrl("some_url/img.jpg"); // set the url after handler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With