 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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

Advertisements
 