开发者

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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜