How to display an image in Java from web?
i have an URL image, and i want to display it in a panel. How can i do开发者_C百科 it ?
One way to achieve this would be to use the URL
class to grab the image from the web, create your ImageIcon
object and then add it onto your JPanel
,
Code is untested, but should demonstrate what you need to do.
URL img = new URL("http://www.example.com/whatever.jpg");
ImageIcon image = new ImageIcon(img);
JLabel label = new JLabel("", image, JLabel.CENTER);
JPanel panel = new JPanel(new BorderLayout());
panel.add( label, BorderLayout.CENTER );
精彩评论