HtmlLabel.java Source code

Java tutorial

Introduction

Here is the source code for HtmlLabel.java

Source

import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class HtmlLabel extends JFrame {
    public HtmlLabel() {
        super("HTML Buttons");
        setSize(400, 300);

        getContentPane().setLayout(new FlowLayout());

        String htmlText = "<html><p><font color=\"#800080\" " + "size=\"4\" face=\"Verdana\">JButton</font> </p>"
                + "<font size=\"2\"><em>" + "with HTML text</em></font></html>";
        JLabel btn = new JLabel(htmlText);
        getContentPane().add(btn);

        WindowListener wndCloser = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        };
        addWindowListener(wndCloser);
        setVisible(true);
    }

    public static void main(String args[]) {
        new HtmlLabel();
    }
}