The following codes explains the JLabel with HTML :
Code:
import java.awt.*;
import javax.swing.*;
public class JLabels extends JFrame {
public static void main(String[] args) {
new JLabels();
}
public JLabels() {
super("HTML used in JLabels");
WindowUtilities.setNativeLookAndFeel();
addWindowListener(new ExitListener());
Container content = getContentPane();
Font font = new Font("Georgia", Font.PLAIN, 20);
content.setFont(font);
String labelText =
"<html><FONT COLOR=BLUE>Blue</FONT> and " +
"<FONT COLOR=YELLOW>Yellow</FONT> Text</html>";
JLabel coloredLabel =
new JLabel(labelText, JLabel.CENTER);
coloredLabel.setBorder
(BorderFactory.createTitledBorder("Mixed Colors"));
content.add(coloredLabel, BorderLayout.NORTH);
labelText =
"<html><B>Bold</B> and <I>Italic</I> Text</html>";
JLabel boldLabel =
new JLabel(labelText, JLabel.CENTER);
boldLabel.setBorder
(BorderFactory.createTitledBorder("Mixed Fonts"));
content.add(boldLabel, BorderLayout.CENTER);
labelText =
"<html>Unity in Diversity " +
"can be seen in this Country." +
"<P>" +
"The Oceans are :" +
"<UL>" +
" <LI>Atlantic" +
" <LI>Pacific" +
" <LI>Indian" +
" <LI>Artic" +
"</UL>";
JLabel fancyLabel =
new JLabel(labelText,
new ImageIcon("images/pic51.gif"),
JLabel.CENTER);
fancyLabel.setBorder
(BorderFactory.createTitledBorder("Contains Many Lines HTML"));
content.add(fancyLabel, BorderLayout.SOUTH);
pack();
setVisible(true);
}
}
Bookmarks