Reputation: 19
I'm trying to display both image from the web and text in JLabel
only the image will show.
jlabel.setText("Hello" + "http://");
Upvotes: 0
Views: 64
Reputation: 3943
JLabel has a setIcon
method which you can use to set the image, pass it an ImageIcon
, which can be created from an URL
:
jlabel.setIcon(new ImageIcon(new URL("http:/...")));
jlabel.setText("Hello");
You can also include an image through HTML directly:
jlabel.setText("<html><img src=\"http://...\"></html>");
Upvotes: 0
Reputation: 4065
Try:
URL url = new URL("http://www.url.com/image.jpg");
Image image = ImageIO.read(url);
jlabel.setIcon(new ImageIcon(image));
jlabel.setText("the text");
Upvotes: 2