Java Swing How to - Create JLabel to hold multiline of text using HTML








Question

We would like to know how to create JLabel to hold multiline of text using HTML.

Answer

//from ww w  .  j  ava  2 s . c  om
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Main {
  public static void main(String[] args) {
    
    JLabel label = new JLabel("<html>Line<br>line<br>line</html>", JLabel.LEFT);
    
    JOptionPane.showMessageDialog(null, label);
    
  }
}