Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Swing loading an Image with ImageIcon from the Internet

807603Jan 9 2008 — edited Jan 9 2008
Hello,

I've tried for a few hours to load a picture from the Internet but I can't get it work!
Local images are shown without any problems. The access to the Internet works also,
I can read a RSS feed for example.

Here is my code sample:
import java.awt.MediaTracker;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class DataModelTest
{
	public static void main(String[] args)
	{
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel panel = new JPanel();
		frame.setContentPane(panel);		
				
		ImageIcon i = null;
		i = new ImageIcon("http://img.stern.de/_content/58/10/581065/hai_500.jpg");
		while ( i.getImageLoadStatus() == MediaTracker.LOADING );
		
		JLabel label = new JLabel(i);
		i.setImageObserver(label);
				
		System.out.println("Adding Image Label");
		panel.add( label );

		frame.setSize(950, 650);
		frame.setVisible(true);
	}
}
I'm thankfull for any help!!

Greets,
cyb
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 6 2008
Added on Jan 9 2008
3 comments
678 views