Create Multiline JLabel with HTML in Java
Description
The following code shows how to create Multiline JLabel with HTML.
Example
/*from www . j av a 2 s . com*/
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
public class Main {
public static void main(String args[]) {
JFrame f = new JFrame("Label Demo");
f.setLayout(new FlowLayout());
f.setSize(200, 360);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label= new JLabel("<html>Use HTML to create<br>" + "a multiline message."
+ "<br>One<br>Two<br>Three");
Border border = BorderFactory.createLineBorder(Color.BLACK);
label.setBorder(border);
f.add(label);
f.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »