Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Using a JLabel and pass in HTML for the text

import javax.swing.JFrame; import javax.swing.JLabel; public class HTMLLabel {   public static void main(String[] a) {     JFrame frame = new JFrame();     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     JLabel label = new JLabel("<html>bold <br> plain</html>");     frame.add(label);     frame.setSize(300, 200);     frame.setVisible(true);   } } If you pass HTML tags to the setText method on a JLabel, the tags must start with "" and end with "".