How do I create multi-line labels in AWT / Swing?

John Zukowski

The AWT Label does not support multiple lines on Label. You would need to create multiple Label components and place them in a Panel (or create your own component).

In Swing 1.1.1 and later, you can place HTML in your labels to get a multi-line label, as in

String htmlLabel = "<html><sup>HTML</sup> <sub><em>Label</em></sub><br>" +
      "<font color="#FF0080"><u>Multi-line</u></font>";
JLabel label = new JLabel(htmlLabel);

If you want to be able to use and to indicate new lines, you would need to define your own UI for the Swing component.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact