Display an image from a URL

Hi,

I've looked through the Java Swing tutorial and I've searched the forums here, but I haven't figured out how to load an image from a URL into my GUI and display it.

I don't want the image to be at certain coordinates, as I am using the FlowLayout. My problem is: how do I load an image from a URL, then display it in a JPanel, such as a JScrollPane?

I'm sorry if I missed any tutorials or similar things about this topic, but if anyone could provide some advice, I would appreciate it.

Thanks,

Dan

[543 byte] By [Djaunla] at [2007-11-26 15:39:45]
# 1

try this:

try {

JLabel label = new JLabel(new ImageIcon(new URL("http://developers.sun.com/forums/img/gold.gif")));

JScrollPane sp = new JScrollPane(label);

}

catch (MalformedURLException x) {

x.printStackTrace();

}

the12huntersa at 2007-7-8 21:58:10 > top of Java-index,Desktop,Core GUI APIs...
# 2
This works fine, thanks for the help.
Djaunla at 2007-7-8 21:58:10 > top of Java-index,Desktop,Core GUI APIs...