JLabel - Show longer text as multiple lines?

Just another example, showing that, with the right layout manager, text wrapped in HTML tags will automatically wrap to the available space...

enter image description here

public class TestHTMLLabel {

    public static void main(String[] args) {
        new TestHTMLLabel();
    }

    public TestHTMLLabel() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                }

                StringBuilder sb = new StringBuilder(64);
                sb.append("<html>I have something to say, it's beter to burn out then to fade away.").
                                append("  This is a very long String to see if you can wrap with in").
                                append("the available space</html>");

                JLabel label = new JLabel(sb.toString());

                JFrame frame = new JFrame("Test");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLayout(new BorderLayout());
                frame.add(label);
                frame.setSize(100, 100);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }    
        });
    }        
}

Use HTML to display the text within the Label.

JLabel fancyLabel = new JLabel("<html>Punch Taskmaster</html>");

(Taskmaster-suggested example added in)


Format with HTML. Works great.

import javax.swing.*;
import java.awt.*;

public class Test {

    public static void main(String[] args) {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(new Dimension(450, 400));
        frame.setLocation(new Point(400, 300));
        frame.setLayout(new BorderLayout());

        final JLabel question = new JLabel("<html>Question:<br>What is love?<br>Baby don't hurt me<br>Don't hurt me<br>No more</html>");
        question.setFont(new Font("Serif", Font.BOLD, 15));
        question.setHorizontalAlignment(JLabel.CENTER);

        frame.add(question);

        frame.setVisible(true);
    }


}

Something like this. The answer give by rcook is very correct. Its just example to show how it can be done.

 b1 = new JLabel("<html>Default Lable I have to resize the
                 <br/> window to see the complete text.</html>");