- Trending Categories
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 add line border to JLabel in Java?
Use the createLineBorder() method to ad line border to JLabel −
Border border = BorderFactory.createLineBorder(Color.ORANGE); label.setBorder(border);
Above, we have set the line border to color orange.
The following is an example to add line border to JLabel −
Example
package my; import java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("Demo Label!", JLabel.RIGHT); label.setFont(new Font("Verdana", Font.PLAIN, 13)); Border border = BorderFactory.createLineBorder(Color.ORANGE); label.setBorder(border); frame.add(label); frame.setSize(500,300); frame.setVisible(true); } }
Output
- Related Articles
- How to add tooltip to JLabel in Java?
- How to add a title to an existing line border in Java?
- How to add empty border to JPanel in Java?
- How to add empty border to a JButton in Java?
- How to add border line below when value changes in an Excel column?
- How to change JLabel font in Java
- How to change JLabel size in Java?
- How to disable a JLabel in Java?
- How to set Line Border color and width with Java?
- Java Program to add Titled Border to Panel in Swing
- How to align JLabel text vertically top in Java?
- How to change JLabel background and foreground color in Java?
- How to add space around table border in HTML?
- How to add horizontal line in HTML?
- How to change text font for JLabel with HTML in Java?

Advertisements