Search code examples
javaswingjlabel

Multiline text in JLabel


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


Solution

  • 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);