- 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 create a LineBorder with BorderFactory class in Java?
To create line border, use the createLineBorder() method. Let us first create a label component −
JLabel label; label = new JLabel("Demo label");
Now, create line border with BorderFactory class. Here, we have also set the color for the line border −
label.setBorder(BorderFactory.createLineBorder(Color.yellow));
The following is an example to create a LineBorder with BorderFactory class −
package my; import javax.swing.BorderFactory; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("Demo label"); label.setFont(new Font("Arial", Font.BOLD, 18)); label.setVerticalAlignment(JLabel.CENTER); label.setBorder(BorderFactory.createLineBorder(Color.yellow)); frame.add(label); frame.setSize(550,350); frame.setVisible(true); } }
Output
- Related Articles
- Create empty border with BorderFactory class in Java?
- How to create etched border for a component using BorderFactory class in Java?
- How to create and set an Empty Border from BorderFactory class in Java?
- How can I set an EtchedBorder from BorderFactory class to a component in Java?
- How to set a MatteBorder from BorderFactory in Java?
- How to create immutable class in Java?
- How to create an immutable class in Java?
- How to create the immutable class in Java?
- How to create an immutable class with mutable object references in Java?\n
- How to create a thread by using anonymous class in Java?
- How to create an object from class in Java?
- How to create your own helper class in Java?
- How to create a class and object in JShell in Java 9?
- How to create a canvas with a class using FabricJS?
- Create Objects of a Class in Java

Advertisements