Multiline text in JLabel

Jessy picture Jessy · Mar 26, 2009 · Viewed 115.1k times · Source

How can I make the text of a JLabel extend onto another line?

Answer

tddmonkey picture tddmonkey · Mar 26, 2009

You can do it by putting HTML in the code, so:

JFrame frame = new JFrame();
frame.setLayout(new GridLayout());
JLabel label = new JLabel("<html>First line<br>Second line</html>");
frame.add(label);
frame.pack();
frame.setVisible(true);