Can I display an image in a JLabel using HTML tags?

Sandip Chitale

Here is a sample -

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ImageInJLabel {
  public static void main(String[] args) {
    JFrame f = new JFrame("ImageInJLabel Example");

    f.getContentPane().setLayout(new BorderLayout());
    JLabel l = new JLabel("", JLabel.CENTER);
    l.setText("<html><center>Hello from jGuru<br>" +
              "<img src="http://www.jguru.com/jguru/images/logos/logos-blu-gr.gif" +
              "width=94 height=109></center></html>");		
    f.getContentPane().add(l, BorderLayout.CENTER);

    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.