import java.awt.*; import javax.swing.*; /** Simple example illustrating the use of JLabel, especially * the ability to use HTML text (Swing 1.1.1 and Java 1.2.2 and * later only!). * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * http://www.corewebprogramming.com/. * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class JLabels extends JFrame { public static void main(String[] args) { new JLabels(); } public JLabels() { super("Using HTML in JLabels"); WindowUtilities.setNativeLookAndFeel(); addWindowListener(new ExitListener()); Container content = getContentPane(); Font font = new Font("Serif", Font.PLAIN, 30); content.setFont(font); String labelText = "WHITE and " + "GRAY Text"; JLabel coloredLabel = new JLabel(labelText, JLabel.CENTER); coloredLabel.setBorder (BorderFactory.createTitledBorder("Mixed Colors")); content.add(coloredLabel, BorderLayout.NORTH); labelText = "Bold and Italic Text"; JLabel boldLabel = new JLabel(labelText, JLabel.CENTER); boldLabel.setBorder (BorderFactory.createTitledBorder("Mixed Fonts")); content.add(boldLabel, BorderLayout.CENTER); labelText = "The Applied Physics Laboratory is a division " + "of the Johns Hopkins University." + "

" + "Major JHU divisions include:" + "

" + ""; JLabel fancyLabel = new JLabel(labelText, new ImageIcon("images/JHUAPL.gif"), JLabel.CENTER); fancyLabel.setBorder (BorderFactory.createTitledBorder("Fancy HTML")); content.add(fancyLabel, BorderLayout.SOUTH); pack(); setVisible(true); } }