Ho provato il metodo da te consigliato, apportando delle modifiche:
codice:
import java.net.*;
import javax.swing.*;
public class ImageProxy {
volatile ImageIcon imageIcon;
final URL imageURL;
Thread retrievalThread;
boolean retrieving = false;
public ImageProxy(URL url) {
imageURL = url;
}
public int getIconWidth() {
if (imageIcon != null) {
return imageIcon.getIconWidth();
} else {
return 800;
}
}
public int getIconHeight() {
if (imageIcon != null) {
return imageIcon.getIconHeight();
} else {
return 600;
}
}
synchronized void setImageIcon(ImageIcon imageIcon) {
this.imageIcon = imageIcon;
}
public void paintIcon(final JLabel c, JLabel g) {
if (imageIcon != null) {
imageIcon.setImage(null);
} else {
Icon loading = new ImageIcon("src//immagini//loading.gif");
g.setIcon(loading);
System.out.println(retrieving);
while (!retrieving) {
retrieving = true;
System.out.println(retrieving);
retrievalThread = new Thread(new Runnable() {
public void run() {
try {
setImageIcon(new ImageIcon(imageURL, ""));
System.out.println(imageURL);
c.setIcon(imageIcon);
} catch (Exception e) {
e.printStackTrace();
}
}
});
retrievalThread.start();
}
}
}
}
richiamandolo così:
codice:
String mapUrlFormat = ("https://maps.googleapis.com/maps/api/staticmap?center....");
URL mapUrl = new URL(mapUrlFormat);
ImageProxy loadingProxy;
loadingProxy = new ImageProxy(mapUrl);
loadingProxy.paintIcon(mapHolder, loadingGif);
ma il thread non riesco a fermarlo quando viene caricata la nuova mappa...non so come fare!!
Dove sbaglio ?