Display simple HTML on JLabel in Java
Description
The following code shows how to display simple HTML on JLabel.
Example
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
/* w w w.j a va2 s . c om*/
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Main extends JFrame {
public static void main(String[] args) {
String lyrics = "<html>Line<br>line<br>line</html>";
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout(10, 10));
JLabel label = new JLabel(lyrics);
panel.add(label, BorderLayout.CENTER);
JFrame f = new JFrame();
f.add(panel);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »