i was trying to put a Gif image to simule "Loading" in a JOptionPane with no results. I tryied with URL, with a Local image, with an absolute path to image but i am only able to put an image (png, jpg...) inside of it. My last try is this
final ImageIcon icon = new ImageIcon(new URL("http://www.archisevilla.org/wp-content/themes/archisevilla/images/loading.gif"));
JOptionPane.showMessageDialog(null, "Cerrando sesión...", "About", JOptionPane.INFORMATION_MESSAGE, icon);
The JOptionPane image's placeholder looks empty when i run this code.
So i wonder: is possible to put a GIF in a JOptionPane, or even in a JFrame?
This is the code i'm using
private void cerrarsesion() throws Exception {
this.dispose();
String path = "/com/icono/loading.gif";
URL url = this.getClass().getResource(path);
System.out.println(url);
ImageIcon icon = new ImageIcon(url);
createTimerClose(10).start();
JOptionPane.showMessageDialog(null, "Cerrando sesión...", "About", JOptionPane.INFORMATION_MESSAGE, icon);
new Login().setVisible(true);
}
It is completely possible and your code must work. Currently I'm running your code and I see the following:
I think you have a problem with accessing the URL of the loading Icon. Maybe a problem with DNS or maybe you are behind a proxy with limited access to some URLs.
Try the following URL in your browser:
http://www.archisevilla.org/wp-content/themes/archisevilla/images/loading.gif
If you can see this loading gif icon in your browser, you must see that in the
JOPtionPane
.If you see the loading.gif icon in your browser but you cannot see it
JOPtionPane
, then try the following:Download it and put it the package which you are writing the above code. for example if you have a class named
Test.java
, put the loading.gif file in the same package asTest.java
exists.Write the following code in the main method of
Test.java
:Now you should see the animated loading.gif in you
JOptionPane
dialog. If you see loading.gif now, you should try finding the problem with accessing that URL from your java code. Sometimes antiviruses or firewalls ban the access of applications such as java.exe (your jvm) for outbound or inbound traffics. Maybe your problem is something like this.But the answer to your question is Yes. It is possible to load and show GIF files in JOptionPanes or JFrames.
Good Luck.