![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create JLabel to hold multiline of text using HTML in Java?
To hold multiline of text, set HTML under JLabel −
JLabel = new JLabel("<html><strong>" + "Line1<br>Line2</strong></html>",JLabel.LEFT);
The above will create multiline text in the JLabel −
Line1 Line2
The following is an example to create JLabel to hold multiline of text −
Example
import java.awt.Font; import javax.swing.*; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Label Example"); JLabel label; label = new JLabel("" + "Line1 Line2",JLabel.LEFT); label.setBounds(100, 100, 100, 30); label.setFont(new Font("Verdana", Font.PLAIN, 13)); frame.add(label); frame.setSize(500,300); frame.setLayout(null); frame.setVisible(true); } }
Output
Advertisements