Multiline JLabels - Java

java, jlabel, swing

Solution

If you don't mind wrapping your label text in an `html` tag, the JLabel will automatically word wrap it when its container's width is too narrow to hold it all. For example try adding this to a GUI and then resize the GUI to be too narrow - it will wrap:

new JLabel("<html>This is a really long line that I want to wrap around.</html>");

Problem

I want `JLabel` text in multiline format otherwise text will be too long. How can we do this in Java?

Original source

Related problems