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 and * later only!). * 1999 Marty Hall, http://www.apl.jhu.edu/~hall/java/ */ 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 = "Red and " + "Blue 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("Multi-line HTML")); content.add(fancyLabel, BorderLayout.SOUTH); pack(); setVisible(true); } }